Cocos2dx 中的CCCallFunc,CCCallFuncN,CCCallFuncND,CCCallFuncO比较

 

qinning199原创,欢迎转载。转载请注明:http://www.cocos2dx.net/?p=27

 

首先看一张图片,表示了CCCallFunc的继承关系:

Cocos2dx 中的CCCallFunc,CCCallFuncN,CCCallFuncND,CCCallFuncO比较

 

1、CCCallFunc,回调,调用不带参数的函数:

 

	CCSequence::actions(CCCallFunc::actionWithTarget(this, callfunc_selector(ExtendActionLayer::onCallBack1)));

	void ExtendActionLayer::onCallBack1()

	{

		flight->runAction(CCTintBy::actionWithDuration(0.5f, 255, 0, 255));

	}

 

 

2、CCCallFuncO,回调,O表示CCObject,CCCallFunco可以带CCObject参数的函数

 

	CCSequence::actions(CCCallFuncO::actionWithTarget(this, callfuncO_selector(ExtendActionLayer::onCallBack2), CCInteger::create(2));



	void ExtendActionLayer::onCallBack2(CCObject* data)

	{

		CCInteger* num = dynamic_cast<CCInteger*>(data);

	    pSender->runAction(CCTintBy::actionWithDuration(num->getValue(), 255, 0, 255));

	}

 

3、CCCallFuncN,回调,N表示CCNode,表示可以传递Node*类型

 

	CCSequence::actions(CCCallFuncN::actionWithTarget(this, callfuncN_selector(ExtendActionLayer::onCallBack3)));

	void ExtendActionLayer::onCallBack3(CCNode* pSender)

	{

	   // 在这个例子里,pSender就是flight,因为是他执行了那个actionF

	   pSender->runAction(CCTintBy::actionWithDuration(1.0f, 255, 0, 255));

	}


 

4、CCCallFuncND,回调,ND表示CCNode和Data,可以传递对象本身和一个void*类型参数,void*表示可以是任意类型的参数

 

	CCSequence::actions(CCCallFuncND::actionWithTarget(this, callfuncND_selector(ExtendActionLayer::onCallBack4), (void *)2));



	void ExtendActionLayer::onCallBack4(CCNode* pSender, void* pData)

	{

	   pSender->runAction(CCTintBy::actionWithDuration(static_cast<float>((int)pData), 255, 0, 255));

	}




你可能感兴趣的:(cocos2dx)