我正在使用此代码为此精灵设置动画:
_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,它不会改变龙,png ......
答案 0 :(得分:0)
检查dragon.png
是否在您的精灵地图集或捆绑资源中。另外,仔细检查文件名中的大小写与您的字符串完全匹配。