2013-11-03 56 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

相關問題