CCCallFuncN:
1 CCCallFuncN *instant = new CCCallFuncN; 2 instant->initWithTarget(this, callfuncN_selector(ActionCallFunc::callback2)); 3 m_grossini->runAction(instant); 4 5 void ActionCallFunc::callback2(CCNode* pSender) 6 { 7 CCSize s = CCDirector::sharedDirector()->getWinSize(); 8 label->setPosition(CCPointMake( s.width/4*2,s.height/2)); 9 pSender->setPosition( ccp(0, 0) ); 10 }
node即指代runAction的node节点;这样当触发callback2的时候即可通过pSender来改变m_grossini的一些状态。
CCCalFuncND:
1 CCCallFuncND *instant2 = new CCCallFuncND; 2 instant2->initWithTarget(this, callfuncND_selector(ActionCallFunc::callback3), (void*)"fgd"); 3 4 void ActionCallFunc::callback3(CCNode* pTarget, void* data) 5 { 6 CCSize s = CCDirector::sharedDirector()->getWinSize(); 7 CCLabelTTF *label = CCLabelTTF::labelWithString("fgd", "Marker Felt", 16); 8 label->setPosition(CCPointMake( s.width/4*3,s.height/2)); 9 addChild(label); 10 }
Data可以将数据指针传进去,不过类型丢了必须强转。
virtual bool initWithTarget (SelectorProtocol *pSelectorTarget, SEL_CallFuncND selector, void *d);现在对SelectorProtocol不太明白,为什么不是node,要是node的话我可以理解成父节点(psender的父节点),但是为啥是SelectorProtocol呢?SelectorProtocol: CCNode是SelectorProtocol的子类