cocos2dx学习笔记之回调函数:定时器schedule,普通回调callfunc,菜单回调menu_selector

函数定义:

typedef void (CCObject::*SEL_SCHEDULE)(float);
typedef void (CCObject::*SEL_CallFunc)();
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
typedef void (CCObject::*SEL_CallFuncND)(CCNode*, void*);
typedef void (CCObject::*SEL_CallFuncO)(CCObject*);
typedef void (CCObject::*SEL_MenuHandler)(CCObject*);
typedef void (CCObject::*SEL_EventHandler)(CCEvent*);
typedef int (CCObject::*SEL_Compare)(CCObject*);

#define schedule_selector(_SELECTOR) (SEL_SCHEDULE)(&_SELECTOR)
#define callfunc_selector(_SELECTOR) (SEL_CallFunc)(&_SELECTOR)
#define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR)
#define callfuncND_selector(_SELECTOR) (SEL_CallFuncND)(&_SELECTOR)
#define callfuncO_selector(_SELECTOR) (SEL_CallFuncO)(&_SELECTOR)
#define menu_selector(_SELECTOR) (SEL_MenuHandler)(&_SELECTOR)
#define event_selector(_SELECTOR) (SEL_EventHandler)(&_SELECTOR)
#define compare_selector(_SELECTOR) (SEL_Compare)(&_SELECTOR)

我在运行项目实例的时候就碰到这样的错误:
error c2440:“类型转换”无法从“void(_ thiscall xx::*)(void)”转换为“cocos2d:SEL_CallFuncN”
结合上面的定义,我发现就是函数参数缺失,对于schedule_selector回调的函数,schedule_selector(Game::callback)
void callback(flaot st)
{ }
在定义callback 时,要注意这个对应类型的参数。
menu_selector:对应参数为CCobject *
callfuncN_selector:对应参数为CCNode *
不过有的地方不写参数也可以编译通过,这点还是没搞明白。

你可能感兴趣的:(cocos2d-x)