本文由qinning199原創,歡迎轉載。轉載請註明:http://www.cocos2dx.net/?p=27函數
首先看一張圖片,表示了CCCallFunc的繼承關係:this
一、CCCallFunc,回調,調用不帶參數的函數:.net
CCSequence::actions(CCCallFunc::actionWithTarget(this, callfunc_selector(ExtendActionLayer::onCallBack1))); void ExtendActionLayer::onCallBack1() { flight->runAction(CCTintBy::actionWithDuration(0.5f, 255, 0, 255)); }
二、CCCallFuncO,回調,O表示CCObject,CCCallFunco能夠帶CCObject參數的函數code
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)); }
三、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)); }
四、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)); }