Search code examples
cocos2d-iphonedelay

change delay in CCAnimation


i would like to know, how can i change delay in 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];

this working fine, but i should change the speed of FPS and i do...

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

but nothing happened...


Solution

  • Stop your walkAction, then change delay of your animation, then recreate action and run it again. If you will look throw the code of CCAnimate, you will see, that delay between frames from CCAnimation object used only during action creation. So this code

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

    will do the trick.