我不知道为什么,但是我的动画不起作用。
我现在尝试通过子画面表但通过一组子画面添加动画单元。
出事了
这是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类的一种方法,因此,要在CCAnimation类(内部称为Enemy)上运行setDisplayFrameEnemy必须扩展CCSprite,而不是CCNode

10-08 08:12