[Solved] How to set a callback when Animate is completed?

Hi, I have an animation that is a sequence of frames:

(AnimMvDown and mySprtAnimate are pointer in my Character class)

AnimMvDown = Animation::createWithSpriteFrames(animFrames, 0.2f);
mySprtAnimate = Animate::create(AnimMvDown);

then I use runAction to play the animation.

this->runAction(mySprtAnimate);

So far so good. Now I want to implement a callback as soon as the Animate is completed. I’ve seen examples on how to do it with an Action, but I do not use Actions.

My goal is to trigger a flag when the character animation is done so I can play it again when it is actually done (continuous walk, so on…).

Any suggestions?

Thanks!

you are using actions

Try this .

   this->runAction(Sequence::create(mySprtAnimate,CallFunc::create(CC_CALLBACK_0(myScene::myFunction, this)), NULL));
1 Like
//Your animation creation of  mySprtAnimate
// ....
//For callback on animation ends
auto callbackAction = CallFunc::create(CC_CALLBACK_0(yourFunc, object))
this->runAction(Sequence::create(mySprtAnimate, callbackAction, nullptr));
//For forever animation:
this->runAction(RepeatForever::create(mySprtAnimate));
1 Like

it worked!
I didnt know how to create a Sequence with an Animate, so I’ve learned something new today. Thanks @nbesshaposhnikov and @Kotaiba! :smile: