2012-03-30 101 views
3

我想知道,如何更改CCAnimation中的延遲?更改CCAnimation中的延遲

_monstrAnim = [CCAnimation animationWithFrames:monstrAnimFrames delay:0.1f]; 
       self.monstr = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"monstr_%d_1.png", currentLevel]]; 
       self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:_monstrAnim restoreOriginalFrame:NO]]; 
       [self.monstr runAction:self.walkAction]; 
       [monstrSpriteSheet addChild:self.monstr z:1]; 

這個工作正常,但我應該改變FPS的速度和我的工作...

  [self.monstr stopAllActions]; 
      [self.monstr runAction:self.walkAction]; 
      [self.monstrAnim setDelay:1]; 

,但什麼都沒有發生......

+0

你什麼時候運行第二個代碼?除非您保留CCAnimation,否則它很可能會在運行後發佈。 – jonsibley 2012-03-30 16:18:13

回答

5

停止你walkAction,然後更改動畫的延遲,然後重新創建動作並再次運行。如果你看看CCAnimate的代碼,你會看到,CCAnimation對象的幀之間的延遲僅在動作創建期間使用。所以這個代碼

[self.monstr stopAllActions]; 
[self.monstrAnim setDelay:1.f]; 
self.walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:_monstrAnim restoreOriginalFrame:NO]]; 
[self.monstr runAction:self.walkAction]; 

將做的伎倆。

+0

工作很好,謝謝! – 2012-03-31 06:41:05

+0

不客氣。順便說一句,我不知道你在你的程序中做了什麼,但是這是一種罕見的情況,我在運行後存儲了動作。它將在運行後保留並在完成後釋放。從這段代碼看來,你的類的walkAction屬性是不必要的。但這只是恕我直言=) – Morion 2012-04-02 08:17:50

+0

好的,謝謝,我感謝它,我會談論它 – 2012-04-02 15:13:46