CCAnimation与无法识别的选择器setDisplayFrame崩溃

时间:2013-11-03 20:59:49

标签: ios objective-c cocos2d-iphone

我不知道为什么,但我的动画不起作用。 我现在尝试通过精灵表添加一个动画单元,但通过一组精灵。 出了点问题 这是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

1 个答案:

答案 0 :(得分:2)

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