我正在使用这段代码来动画这个精灵:
_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 ...