今天学习cocos2dx的时候发现原来所有选择器要求传递的回调函数的参数是有限制的,看了库中的定义后就遇到的整理如下,仅供参考,Cocos2dx版本2.2.3:
?
选择器参数说明
schedule_selector(浮点数)[float dt]
?
callfunc_selector(无参数)[void]
?
callfuncn_selector(节点)[CCNode *node]
?
callfuncND_selector(节点,任意参数)[CCNode *node,void *any]
?
callfuncO_selector(对象)[CCObject *pSender]
?
menu_selector(对象)[CCObject *pSender]
?
event_selector(事件)[CCEvent *event]
?
compare_selector(对象)[CCObject *pSender]
?
?
原始的声明如下
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)
?
?
?
cccontrol_selector(对象,整数)[CCObject *pSender,CCControlEvent]
?
原始声明如下:
typedef
unsigned
int
CCControlEvent;
?
typedef
void
(CCObject::*SEL_CCControlHandler)(CCObject*,
CCControlEvent);
?
对应选择器宏:
#define
cccontrol_selector(_SELECTOR)
(SEL_CCControlHandler)(&_SELECTOR)