首页 > 代码库 > cocos2d 动作回调函数

cocos2d 动作回调函数

// on "init" you need to initialize your instancebool HelloWorld::init(){    //////////////////////////////    // 1. super init first    if ( !CCLayer::init() )    {        return false;    }        CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();    CCSize winSize = CCDirector::sharedDirector()->getWinSize();     auto *png1=CCSprite::create("1.png");    png1->setPosition(ccp(0,120));    addChild(png1);     CCFiniteTimeAction *action = CCSequence::create(         CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)),         CCCallFunc::create(this, callfunc_selector(HelloWorld::actionCallback)), NULL);      CCFiniteTimeAction *actionN = CCSequence::create(         CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)),         CCCallFuncN::create(this, callfuncN_selector(HelloWorld::actionCallbackN)), NULL);      CCFiniteTimeAction *actionND = CCSequence::create(         CCMoveBy::create(2.0f, CCPointMake(winSize.width / 2, 0)),         CCCallFuncND::create(this, callfuncND_selector(HelloWorld::actionCallbackND), (void *) "Callback Data"), NULL);          png1->runAction(action);     //png1->runAction(actionN);     //png1->runAction(actionND);     return true;}void HelloWorld::actionCallback(){    CCSize winSize = CCDirector::sharedDirector()->getWinSize();    CCLabelTTF *label = CCLabelTTF::create("Action Callback!", "Marker Felt", 32);    label->setPosition(ccp(winSize.width / 2, winSize.height / 2));    this->addChild(label);}void HelloWorld::actionCallbackN(CCNode *pSender) {     CCSprite *sprite = (CCSprite *) pSender;      // 回调变红色      sprite->setColor(ccRED); } void HelloWorld::actionCallbackND(CCNode *pSender, void *data) {     CCSize winSize = CCDirector::sharedDirector()->getWinSize();     CCSprite *sprite = (CCSprite *) pSender;      // 回调变蓝色      sprite->setColor(ccBLUE);          // 接收回调数据      CCLabelTTF *label = CCLabelTTF::create((char *) data, "Marker Felt", 32);     label->setPosition(ccp(winSize.width / 2, winSize.height / 2));     this->addChild(label);      CCLog((char *) data); } 

 

cocos2d 动作回调函数