Stoping a running action when adding a new one

Stoping a running action when adding a new one
0.0 0


Hi guys,

I have this code:

cocos2d::CCAnimation* pIdleAnimLayer0 = cocos2d::CCAnimation::createWithSpriteFrames( &m_JeffreyF[0], 0.083f );
cocos2d::CCAction* pIdleLayer0 = cocos2d::CCRepeatForever::create( cocos2d::CCAnimate::create( pIdleAnimLayer0 ) );
m_pFrogLayer0->runAction( pIdleLayer0 );

Which runs an idle animation forever. But when I run another animation in the same node the two animations
run at the same time
I remember it could be done in cocos2d-1.0.1-x-0.13.0-beta just doing another runAction with the new animation.

Any advice would be fantastic!



You can use stopAllActions() if you run no actions except the one you need to stop. Or you can store pointer to pIdleLayer0 elsewhere and then use stopAction(pointer). Or you can setTag to pIdleLayer0 and then use stopActionByTag.


Hi Igor,

I know I can stop the action but the thing want is just doing runAction with the new action without having to stop the forever action which was
running. This way I don’t have to run again the forever action when the new one finish.


I don’t think stopping all running actions when adding a new one must be the default behavior. You can stop them if you need or not - it’s more generic. But I agree that some kind of mechanism to pause/resume specific action would be nice.

In your case you can stop your forever action and add a seqence consisting of new action and forever action.


this is how i do it…

CCAnimate *anim = CCAnimate::create(animation);
//stop the repeating action if its’ running.
//update it with the new animation.
CCAssert(m_pRepeatAction->initWithAction(anim), “initWithAction expected to pass”);
//run the animation action.

This is a member function of a class that inherits CCSprite, basically the idea is to track the pointer or the tag of the action that is running the animation, remove it and add the new animation.


As far as i know , a sequence action can’t contains forever action.
In u case, i think u can do just like this,
u another action,
so, u can do almost of things in the two callback functions, just like stopActionByTag, pIdleLayer0~~>setTag() may be necessary