How do I call a global function after a delay?

How do I call a global function after a delay?
0.0 0


I have a function that is not part of a class that I want to call after a delay.


    CCDelayTime *delayAction = CCDelayTime::actionWithDuration(3.0f);
    CCCallFunc *callSelectorAction = CCCallFunc::actionWithTarget( this, callfunc_selector( ShowWinScreen ) );
    helloWorldScene->runAction( CCSequence::actions( delayAction, callSelectorAction, NULL ) );

void ShowWinScreen()

Now, if I make ShowWinScreen part of the class, such as HelloWorld::ShowWinScreen() then it works, however I don’t want this function part of the class. How can I make a global function call after a delay? Thanks for all the help.


What problem did you meet?
May be you should define ShowWinScreen before the definition of HelloWorld.


Even with ShowWinScreen defined earlier, or put into the header I still get the same issue:

callfunc_selector says “invalid type conversion”, and at compile this:

error C2440: ‘type cast’ : cannot convert from ‘void (__cdecl *)(void)’ to ‘cocos2d::SEL_CallFunc’


Hi Chad,
Instead of writing void ShowWinScreen(), type voidShowWinScreen(CCNode* sender)
don’t forget to make changes in header file as well.

You problem will be solved :slight_smile: