cocos2dx 中的SEL_Callfunc,SEL_CallfuncN,SEL_CallfuncNd的用法

前端之家收集整理的这篇文章主要介绍了cocos2dx 中的SEL_Callfunc,SEL_CallfuncN,SEL_CallfuncNd的用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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 init(CCObject* _pSelectorTarget,Sel_Schedule _selector)
{
pSelectorTarget = _pSelecotrTarget.
selector = _pSelector;
}
(pSelectorTarget -> *selector) (f_time) 函数指针调用传递参数


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

原文链接:https://www.f2er.com/cocos2dx/343002.html

猜你在找的Cocos2d-x相关文章