Stop Sprite Animation in cocos2d

132 views Asked by At

This is the code to show sprite sheet animation if something happens in the game, animation works perfect but it is not stopping after the animation frames sequence complete, i had done so many things to stop the animation, but nothing is giving me solution, here is my code

if(m_bEffectChangeColor){

`

        m_gamecoinffect = [CCSprite spriteWithSpriteFrameName:@"powerup0001"];
          [self addChild:m_gamecoinffect z:3];



        CCAnimate *coineffect = [CCAnimate actionWithSpriteSequence:@"powerup%04d" numFrames:30 delay:0.1f restoreOriginalFrame:NO];
        [m_gamecoinffect runAction:[CCRepeatForever actionWithAction:coineffect]];

        m_gamecoinffect.position = ptEffectPos;

        CCCallBlock *block = [CCCallBlock actionWithBlock:^{
            //[m_gamecoinffect stopAllActions];
            [self removeChild:m_gamecoinffect cleanup:YES];

        }];
        CCDelayTime *time = [CCDelayTime actionWithDuration:1];
        [m_gamecoinffect runAction:[CCSequence actions:time, block, nil]];

`

Above code i tried to add timer and everything i know, but nothing is working,,, i would like to stop animation and remove those sprite from the layer.

Thanks in advance.

1

There are 1 answers

1
bunty On BEST ANSWER

The animation does not stop because the CCRepeatForever is the action which animates forever means continuously. Change below line:

[m_gamecoinffect runAction:[CCRepeatForever actionWithAction:coineffect]];

With

[m_gamecoinffect runAction:coineffect];