1,进入这三个源码中,可以看到这几句代码分别为
typedef void (CCobject::*SEL_SCHEDULE)(float); //函数指针,函数有一个参数float,返回类型为void
typedef void (CCobject::*SEL_CallFunc)();//函数指针,函数无参数,返回类型为void
typedef void (CCobject::*SEL_CallFuncN)(CCNode*)//函数指针,函数有一个参数,返回类型为void
typedef void (CCobject::*SEL_CallFuncND)(CCNode*,void*);/函数指针,函数有一个参数,返回类型为void
typedef void (CCobject::*SEL_CallFuncND)(CCNode*,void*);/函数指针,函数有两个参数,返回类型为void
typedef void (CCobject::*SEL_CallFuncO)(CCObject*);/函数指针,函数有一个参数,返回类型为void
typedef void (CCObject::SEL_MenuHandler)(CCObject*);// 函数指针,函数有一个参数,返回类型为void
2,这些都是Cocos2dx中定义的宏
#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)
3,下面看一些经常使用的方法void Daojishi(float dt);//必须要有参数才能调用update
我们可能都会用到,如 this->schedule(schedule_selector(myTest::Daojishi));
void add(CCobject * pSender);
或者item->setTarget(menu_selector(myTest::add));
CCNode * node
SEL_CallFuncND selectorND;// 函数指针
或者 CCObject *pSelectorTarget; SEL_SCHEDULE selector;
4,如果我们自己定义个回调函数,可以这样来写
void ArmatureSprite::ArmatureAttackcall(CCNode* _pNode1,SEL_CallFuncND _pselector1,void *_pd1,149)">CCNode* _pNode2,149)">SEL_CallFuncND _pselector2,166)">void* _pd2){
pNode1 = _pNode1;
pSelector1 = _pselector1;
pD1 = _pd1;
pNode2 = _pNode2;
pSelector2 = _pselector2;
pD2 = _pd2;
_armatureBaoZha->ArmatureAttackcall(NULL,NULL, NULL,this,callfuncND_selector(BaseSpecialEffectsGetReward::HD_OpenStarBox),tempStr);
}
menu_selector(HelloWorld::menuCloseCallback));
Object::*SEL_Cal