0
我使用此代碼這個動畫精靈:精靈動畫
_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變更...
這是一樣的,我敢肯定。 – 2013-04-11 17:10:54
嗯,你使用單獨的PNG文件或spriteAtlases?我假設'self'是'GameObject,不是嗎?第二個代碼片段在哪個方法中? – ssantos 2013-04-11 17:38:16
我正在使用Sprites.pvr.ccz「和Sprites.plist。沒有自己不是一個遊戲對象,而_ship是一個遊戲對象。我再次嘗試,現在每當我重新開始遊戲時,這個精靈都會改變...... for解釋:start1 dragon.png ...重新啓動。start2 dragon2.png ...重新啓動。start3 dragon.png ecc ...真的,我不明白爲什麼,謝謝你的回答。 – 2013-04-11 19:08:05