In cocos2d-x, the following piece of code is supposed to run the callback function after a delay. What do I need to do to fix the error?
bool LoadingLevelScreen::initialise() {
// set up the time delay
CCDelayTime *delayAction = CCDelayTime::actionWithDuration(0.5f);
// perform the selector call
CCCallFunc *callSelectorAction = CCCallFunc::actionWithTarget(
this, callfunc_selector( LoadingLevelScreen::menuCallbackStart ) );
// run the action
this->runAction( CCSequence::actions(
delayAction, callSelectorAction, NULL ) );
}
void LoadingLevelScreen::menuCallbackStart(CCObject * pSender)
{
}
Compiler Error:
error C2440: 'type cast' :
cannot convert from 'void (__thiscall LoadingLevelScreen::* )(cocos2d::CCObject *)'
to 'cocos2d::SEL_CallFunc'
Pointers to members have different representations; cannot cast between them
Either remove the
CCObject*parameter inmenuCallbackStart()method (becauseCCCallFunc::actionWithTarget()expects a method with no arguments), or changeCCCallFunctoCCCallFuncOwhich expects a method with aCCObject*as argument, like so:where
myObjectis aCCObject *that will be passed to your method as the argument.Note that
callfunc_selector()is just a macro that typecasts your method toSEL_CallFunc:BTW
::actionWithTarget()is being deprecated, so use::create()instead.