2013-11-03 55 views
2

我不知道为什么,但我的动画不起作用。 我想通过精灵表添加一个动画单元,但通过一组精灵。 而出了差错 这里是init方法的代码:CCAnimation与无法识别的选择器崩溃setDisplayFrame

@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; 
} 

的错误是:- [敌人setDisplayFrame:]:无法识别的选择发送到实例0x8929bd0

+0

'Enemy'扩展'CCSprite'吗? – ssantos

+0

父母是CCNode –

+0

然后就是这个问题。请看看我的答案。 – ssantos

回答

2

setDisplayFrame的方法的CCSprite类,所以为了运行CCAnimationEnemy类(其内部呼叫setDisplayFrame),Enemy必须扩展CCSprite,而不是CCNode

+0

是的,那是原因。谢谢:) –

+0

很高兴帮助。 – ssantos

相关问题