ios - CCAnimation 因无法识别的选择器 setDisplayFrame 而崩溃

标签 ios objective-c cocos2d-iphone

我不知道为什么,但我的动画不起作用。 我现在尝试通过 Sprite 表但通过一组 Sprite 添加一个动画单元。 出了问题 下面是init方法的代码:

@implementation Enemy
-(id) initAt:(CGPoint)pos
{
    if([super init])
    {
        self.position = pos;
        CCSprite *start_sprite = [CCSprite spriteWithFile:@"unit1_00000.png"];
        start_sprite.position  = ccp(0,0);
        [self addChild:start_sprite z:2];

        const int FRAMES_COUNT = 10;
        NSMutableArray* frames = [[NSMutableArray alloc]initWithCapacity:FRAMES_COUNT];
        for (int i = 0; i < FRAMES_COUNT; i++)
        {
            NSString* file = [NSString stringWithFormat:@"unit1_0000%i.png", i];
            CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
            CGSize texSize = texture.contentSize;
            CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
            CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
            [frames addObject:frame];
        }


        _default_animation = [CCAnimation animationWithSpriteFrames:frames delay:0.1f];
        _current_anim_action = [CCAnimate actionWithAnimation:_default_animation];
        CCRepeatForever* repeat = [CCRepeatForever actionWithAction:_current_anim_action];
        [self runAction:repeat];
    }
    return self;
}

错误如下:-[Enemy setDisplayFrame:]:无法识别的选择器发送到实例 0x8929bd0

最佳答案

setDisplayFrameCCSprite 类的方法,因此为了在 Enemy 类上运行 CCAnimation (它内部调用 setDisplayFrame),Enemy 必须扩展 CCSprite,而不是 CCNode

关于ios - CCAnimation 因无法识别的选择器 setDisplayFrame 而崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19758054/

相关文章:

ios - 如何检测设备是否为 iOS 8.3 中的 iPad?

iphone - 自定义 UISegmentedControl,添加背景图片和选择的段色调颜色

ios - swift 中的 CDPieMenu (cocoapod)

iphone - 使用简单音频引擎的声音循环之间的轻微停顿

ipad - 有谁知道 kCCDirectorProjection2D 是做什么的?

iphone - 如何使 iphone 和 iphone4-retina 兼容的应用程序(在 cocos2d 中完成)轻松适应 ipad?

ios - 是否可以在容器中显示 UIDocumentInteractionController?

ios - 添加后 GMSMarker 未显示在 map 上

iphone - iOS GM GridView 如何重用GM GridView Cell 单元格?

iphone - UIPickerView 的大小设置不正确