CCSize s = CCDirector::sharedDirector()->getWinSize();
CCSprite *sp = CCSprite::create("CloseSelected.png");
sp->setPosition(ccp(s.width/2,s.height/2));
addChild(sp);
1、执行回调函数
CCMoveTo *move = CCMoveTo::create(2,ccp(s.width,s.height));
CCActionInstant *func = CCCallFunc::create(this,callfunc_selector(MyScene::funcCallback)); //要回调的函数,函数形式为void funcCallback();
sp->runAction(CCSequence::create(move,func,NULL));
2、可获取动作主体的回调函数
CCMoveTo *move = CCMoveTo::create(2,ccp(s.width,s.height));
CCActionInstant *func = CCCallFuncN::create(this,callfuncN_selector(MyScene::funcNCallback));//回调函数的形式void funcNCallback(CCNode *pSender);
sp->runAction(CCSequence::create(move,func,NULL));
void MyScene::funcNCallback(CCNode *pSender)
{
CCSprite *sp = (CCSprite *)pSender; //获取精灵对象
}
3、可同时传输数据的回调函数
CCMoveTo *move = CCMoveTo::create(2,ccp(s.width,s.height));
CCActionInstant *func = CCCallFuncND::create(this,callfuncND_selector(MyScene::funcNDCallback),(void*)10); //要回调的函数void funcNDCallback(CCNode *pSender,void* Data);
sp->runAction(CCSequence::create(move,func,NULL));
void MyScene::funcNDCallback(CCNode *pSender,void* Data)
{
CCSprite *sp = (CCSprite *)pSender;
int a = (int)Data; //获取数据
}
4、//可传入对象CCCallFuncO
5、提速
CCMoveTo *move = CCMoveTo::create(2,ccp(s.width,s.height));
CCSpeed *speed = CCSpeed::create(move,2);//参数1:提速前的动作,参数2:提速的倍数,这里是提高两倍
sp->runAction(speed);
6、跟随
CCMoveTo *move = CCMoveTo::create(2,ccp(s.width,s.height));
CCFollow *follow = CCFollow::create(sp, CCRectZero); //sp是被跟随者,CCRectZero跟随的区域范围,超过就不能跟
sp->runAction(move);
this->runAction(follow);//this是跟随者,这里是场景