2012-03-30 75 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