How to call a void function inside the sequence?

Good day,

I have this:

void TheClass:Method1()
{
    cocos2d::MoveBy* moveAction = cocos2d::MoveBy::create( 3, cocos2d::Vec2( 0, 10 ) );
    cocos2d::Sequence* theSequence = cocos2d::Sequence::create(moveAction, TheClass:Method2, nullptr);
    someSprite->runAction(theSequence);
}
void TheClass:Method2()
{
    // run some code
}

Why can’t I run this?

I am using coco2d-x ver 3.8.

Thank you :smile:

Try this

cocos2d::Sequence* theSequence = cocos2d::Sequence::create(moveAction, CallFuncN::create(CC_CALLBACK_0(TheClass:Method2, this)), nullptr);

It should work.

what is the “this” in this code?

this is the class (TheClass) which contains “Method2”.
You can also use CallFunc:

auto sequence = Sequence::createWithTwoActions(moveAction, CallFunc::create([&](){Method2(); }));

I tried the code but the application freezes.