1
所以這裏的問題是當我創建一個動畫射彈時,一切都很好。只要用戶創建第二個,第一個停止動畫。Cocos2D - 當我動畫第二個精靈時,首先停止動畫
好了,這裏就是我如何設置它在我的初始化:
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"acorns.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"acorns.png"];
[self addChild:spriteSheet];
NSMutableArray *flyingFrames = [NSMutableArray array];
for(int i = 1; i <= 4; ++i) {
[flyingFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"acorn%d.png", i]]];
}
CCAnimation *flying = [CCAnimation
animationWithFrames:flyingFrames delay:0.5f];
self.flying = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:flying restoreOriginalFrame:NO]];
然後,我創建子彈的方法被稱爲當用戶點擊屏幕,我做的:
CCSprite *bullet = [CCSprite spriteWithSpriteFrameName:@"acorn1.png"];
bullet.position = CGPointMake(140.0f, FLOOR_HEIGHT+145.0f);
[bullet runAction:_flying];
[self addChild:bullet z:9];
[bullets addObject:bullet];
因此,用戶第一次點擊時,一切正常。第二次,創建了動畫子彈,但現有的子彈停止動畫,等等。