Forum > C++ > How do I call a global function after a delay?

How do I call a global function after a delay?

By HkySk8r187 Posted 2011-12-01 19:44 Comments 3
  • Posts: 72

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.

  • Posts: 2082
  • Location: Xiamen, China

#1 RE: 2011-12-01 22:07

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

  • Posts: 72

#2 RE: 2011-12-02 13:15

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’

  • Posts: 32
  • Location: Bikaner

#3 RE: 2011-12-08 04:46

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 :)

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps