首页 > 代码库 > 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 动作回调函数
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。