Execute logic on action stop

So, I want to execute some logic when an action has finished running. At the moment, I have created a new class inheriting from the JumpBy (my action) class and overriding the stop() method. However, that stop() is not getting called.

What’s the correct way to go about this?

(sprite->runAction() performs the action successfully, but on stop it doesn’t execute the stop() method)

I am not sure about the stop() method… I did it inside the update(float t) function:

void aClass::update(float t)
{
    //perform your animations or call super

    if (isDone())
    {
        //The action has ended. Call the ending methods here.
    }
}

This is very easy. The correct way to do this is with an action sequence. You can pass any number of actions to the sequence which will be called sequentially, so if you want to do something and then execute some logic you would use the CallFunc action.

// Create a JumpBy action
auto jumpBy = JumpBy::create(…)

// Create a callfunc action
auto callback = CallFunc::create(CC_CALLBACK_0(SomeClass::callbackFunction, this));

// Run the action in a sequence
sprite->runAction(Sequence::create(jumpBy, callback, NULL));

implement your callback function:

void SomeClass::callbackFunction() { // do something }

stop() isn’t necessarily called. For example if you use it wrapped in a Repeat action, stop() is called only at the last repeat. If you put it into a RepeatForever action it’s never called.

So I second @UKDeveloper99 's suggestion.
You can also use CallFunc with lambda:

sprite->runAction(
    Sequence::create(
        JumpBy::create(/*...*/), 
        CallFunc::create([this]() {
            // do your stuff
        }),
        nullptr
    )
);