このコードを使用して、このスプライトをアニメーション化しています。
_ship = [[GameObject alloc] initWithSpriteFrameName:@"SpaceFlier_sm_1.png" world:_world shapeName:@"SpaceFlier_sm_1" maxHp:10 healthBarType:HealthBarTypeGreen];
CCSpriteFrameCache * cache =
[CCSpriteFrameCache sharedSpriteFrameCache];
CCAnimation *animation = [CCAnimation animation];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_2.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_3.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_4.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_5.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_6.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_7.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_8.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"SpaceFlier_s_2.png"]];
animation.delayPerUnit = 0.05;
[_ship runAction:
[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:animation]]];
それは非常にうまく機能します。次に、このコードを使用して別のスプライトをアニメーション化しようとすると、機能しません。
この上:
if ((self = [super initWithSpriteFrameName:@"dragon.png" world:world shapeName:@"Boss_ship" maxHp:50 healthBarType:HealthBarTypeRed])) {
_layer = layer;
CCSpriteFrameCache * cache =
[CCSpriteFrameCache sharedSpriteFrameCache];
CCAnimation *animation = [CCAnimation animation];
[animation addSpriteFrame:
[cache spriteFrameByName:@"dragon2.png"]];
[animation addSpriteFrame:
[cache spriteFrameByName:@"dragon.png"]];
animation.delayPerUnit = 0.05;
[self runAction:
[CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:animation]]];
dragon2.pngしか見えない、dragon,pngでは変わらない…