2012-06-12 41 views
0

我2個精靈運行的動畫,就像這樣:「Cocos2d」複製的操作沒有響應?

-(void) startFootballAnimation { 

CCAnimation* footballAnim = [CCAnimation animationWithFrame:@"Football" frameCount:60 delay:0.005f]; 
spiral = [CCAnimate actionWithAnimation:footballAnim]; 
CCRepeatForever* repeat = [CCRepeatForever actionWithAction:spiral]; 
[self runAction:repeat]; 
[secondFootball runAction:[[repeat copy] autorelease]]; 
} 

我遇到的問題是,當我把這個方法:

- (void) slowAnimation { 

[spiral setDuration:[spiral duration] + 0.01]; 
} 

....它只是減慢第一個精靈的動畫而不是第二個。我是否需要做一些與複製操作不同的事情來讓他們對動畫放緩做出反應?

+0

如果我沒有弄錯,你應該對兩個不同的對象使用2個動作。否則,你無法區分它們。雖然我不是100%肯定的。 –

+0

這意味着我將不得不爲另一個精靈創建完全相同的動作! – Stephen

回答

2

對對象的調用複製也會複製內部操作。你可以通過在CCAction.m中查看CCRepeatForevercopyWithZone:的實現來看到這一點。這很好,因爲一個動作只能有一個目標節點。

所以是的,要在上面的評論中回答你的問題,你需要爲每個精靈創建一個新的動作。您可以使用複製方法快速複製您的操作,但您必須單獨對其行爲應用更改(例如,您的slowAnimation)。