亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

[cocos2d-x]動作+場景切換

發布時間:2020-07-06 01:20:32 來源:網絡 閱讀:294 作者:蓬萊仙羽 欄目:游戲開發

實現一個demo,具備以下功能:

1.實現帶一個參數或者兩個參數的方法回調。

2.實現按鈕圍繞屏幕轉動。

3.實現場景的切換(中間要有過渡場景,以便實現前一個場景資源的釋放)。

4.實現label的循環旋轉+不停的來回移動。

效果圖:

[cocos2d-x]動作+場景切換[cocos2d-x]動作+場景切換[cocos2d-x]動作+場景切換[cocos2d-x]動作+場景切換

實現代碼:

HelloWorldScene.h:

#ifndef __HELLOWORLD_SCENE_H__ #define __HELLOWORLD_SCENE_H__  #include "cocos2d.h" using namespace cocos2d; class HelloWorld : public cocos2d::CCLayer { public:     // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)     virtual bool init();      // there's no 'id' in cpp, so we recommend to return the class instance pointer     static cocos2d::CCScene* scene();          // a selector callback     void menuCloseCallback(CCObject* pSender);      // preprocessor macro for "static create()" constructor ( node() deprecated )     CREATE_FUNC(HelloWorld);          //函數回調,帶一個參數的回調     void funcN_CallBack(void *sender);     //帶兩個參數的回調     void funcND_CallBack(void *sender,void *data); };  #endif // __HELLOWORLD_SCENE_H__

HelloWorldScene.cpp:

#include "HelloWorldScene.h" #include "SimpleAudioEngine.h" #include "SecondScene.h" using namespace cocos2d; using namespace CocosDenshion;  CCScene* HelloWorld::scene() {     // 'scene' is an autorelease object     CCScene *scene = CCScene::create();          // 'layer' is an autorelease object     HelloWorld *layer = HelloWorld::create();      // add layer as a child to scene     scene->addChild(layer);      // return the scene     return scene; }  // on "init" you need to initialize your instance bool HelloWorld::init() {     //////////////////////////////     // 1. super init first     if ( !CCLayer::init() )     {         return false;     }      /////////////////////////////     // 2. add a menu item with "X" image, which is clicked to quit the program     //    you may modify it.      // add a "close" icon to exit the progress. it's an autorelease object     CCMenuItemImage *pCloseItem = CCMenuItemImage::create(                                         "CloseNormal.png",                                         "CloseSelected.png",                                         this,                                         menu_selector(HelloWorld::menuCloseCallback) );     pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );      // create menu, it's an autorelease object     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);     pMenu->setPosition( CCPointZero );     this->addChild(pMenu, 1);                          /////////////////////////////     // 3. add your codes below...      // add a label shows "Hello World"     // create and initialize a label     CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);      // ask director the window size     CCSize size = CCDirector::sharedDirector()->getWinSize();          CCCallFuncN *callFuncN = CCCallFuncN::create(this, callfuncN_selector(HelloWorld::funcN_CallBack));     pLabel->runAction(callFuncN);          // position the label on the center of the screen     pLabel->setPosition( ccp(size.width / 2, size.height - 20) );      // add the label as a child to this layer     this->addChild(pLabel, 1);          CCLabelTTF* pLabel2 = CCLabelTTF::create("hi", "Thonburi", 34);          //帶兩個參數的回調     CCString *str = CCString::create("帶兩個參數的回調");     str->retain();     CCCallFuncND *callFuncND = CCCallFuncND::create(this,callfuncND_selector(HelloWorld::funcND_CallBack),str); //最后一個參數是void*可以是任意類型     pLabel2->runAction(callFuncND);          pLabel2->setPosition(ccp(size.width / 2 + 20,40));     this->addChild(pLabel2,1);          // add "HelloWorld" splash screen"     CCSprite* pSprite = CCSprite::create("HelloWorld.png");      // position the sprite on the center of the screen     pSprite->setPosition( ccp(size.width/2, size.height/2) );      // add the sprite as a child to this layer     this->addChild(pSprite, 0);          return true; }  int i=0; void HelloWorld::menuCloseCallback(CCObject* pSender) {          CCSize size = CCDirector::sharedDirector()->getWinSize();     CCMenuItem *item = (CCMenuItem *)pSender; /******舒緩動作********************************************************/     //    CCActionInterval *action = CCMoveTo::create(2, ccp(20,size.height-20));     //    item->runAction(action);      /******先慢再快********************************************************/     //    CCMoveTo *move = CCMoveTo::create(3, ccp(size.width-20, size.height-20));     //    CCActionInterval *ease = CCEaseInOut::create(move, 4);     //    item->runAction(ease);      /*******循環移動**********************************************************/     //float duration = CCRANDOM_0_1()*5+1;     float duration = 0.1f;     CCMoveTo *move1 = CCMoveTo::create(duration, ccp(20, 20));     CCMoveTo *move2 = CCMoveTo::create(duration,ccp(20, size.height-20));     CCMoveTo *move3 = CCMoveTo::create(duration, ccp(size.width - 20, size.height-20));     CCMoveTo *move4 = CCMoveTo::create(duration, ccp(size.width-20, 20));     CCSequence *sequence = CCSequence::create(move1,move2,move3,move4,NULL);     //CCRepeatForever *repeat = CCRepeatForever::create(sequence);     item->runAction(sequence);     i++;          //跳轉     if (i==2) {         //replease切換場景 //        SecondScene *sense = SecondScene::create(); //        CCScene *secScene = CCScene::create(); //        secScene->addChild(sense,0); //        CCDirector::sharedDirector()->replaceScene(secScene);                  //push切換場景         CCTransitionFade *secondScene = CCTransitionFade::create(1.0f,SecondScene::scene(),ccGREEN);         CCDirector::sharedDirector()->pushScene(secondScene);     } }  //回調函數 void HelloWorld::funcN_CallBack(void *sender) {     CCLabelTTF *label = (CCLabelTTF *)sender;     label->setString("帶一個參數的回調");     CCLog("CallFuncN的回調"); }  //帶兩個參數的回調 void HelloWorld::funcND_CallBack(void *sender,void *data) {     CCString *str = (CCString *)data;     CCLabelTTF *label = (CCLabelTTF *)sender;     label->setString(str->getCString()); }

SecondScene.h:

#ifndef ___013_9_4___________SecondScene__ #define ___013_9_4___________SecondScene__  #include <iostream> #include "cocos2d.h" using namespace cocos2d; class SecondScene : public cocos2d::CCLayer { public:     // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)     virtual bool init();          // there's no 'id' in cpp, so we recommend to return the class instance pointer     static cocos2d::CCScene* scene();          // a selector callback     void menuCloseCallback(CCObject* pSender);          // preprocessor macro for "static create()" constructor ( node() deprecated )     CREATE_FUNC(SecondScene);      };  #endif /* defined(___013_9_4___________SecondScene__) */

SecondScene.cpp:

#include "SecondScene.h" #include "SimpleAudioEngine.h"  using namespace cocos2d; using namespace CocosDenshion;  CCScene* SecondScene::scene() {     // 'scene' is an autorelease object     CCScene *scene = CCScene::create();          // 'layer' is an autorelease object     SecondScene *layer = SecondScene::create();          // add layer as a child to scene     scene->addChild(layer);          // return the scene     return scene; }  // on "init" you need to initialize your instance bool SecondScene::init() {     //////////////////////////////     // 1. super init first     if ( !CCLayer::init() )     {         return false;     }          CCMenuItemImage *pCloseItem = CCMenuItemImage::create(                                                           "CloseNormal.png",                                                           "CloseSelected.png",                                                           this,                                                           menu_selector(SecondScene::menuCloseCallback) );     pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );          // create menu, it's an autorelease object     CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);     pMenu->setPosition( CCPointZero );     this->addChild(pMenu, 1);          CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);          // ask director the window size     CCSize size = CCDirector::sharedDirector()->getWinSize();          // position the label on the center of the screen          pLabel->setPosition( ccp(size.width / 2, size.height / 2) );     pLabel->setAnchorPoint(ccp(0.5, 0.5));     pLabel->setTag(10);     // add the label as a child to this layer     this->addChild(pLabel, 1); } void SecondScene::menuCloseCallback(CCObject* pSender) { //        CCDirector::sharedDirector()->end(); //     //    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) //        exit(0); //    #endif          CCSize size = CCDirector::sharedDirector()->getWinSize();     CCMenuItem *item = (CCMenuItem *)pSender; /******舒緩動作********************************************************/     //    CCActionInterval *action = CCMoveTo::create(2, ccp(20,size.height-20));     //    item->runAction(action);      /******先慢再快********************************************************/     //    CCMoveTo *move = CCMoveTo::create(3, ccp(size.width-20, size.height-20));     //    CCActionInterval *ease = CCEaseInOut::create(move, 4);     //    item->runAction(ease);           /*******循環移動**********************************************************/     //float duration = CCRANDOM_0_1()*5+1;     float duration = 0.1f;     CCMoveTo *move1 = CCMoveTo::create(duration, ccp(20, 20));     CCMoveTo *move2 = CCMoveTo::create(duration,ccp(20, size.height-20));     CCMoveTo *move3 = CCMoveTo::create(duration, ccp(size.width - 20, size.height-20));     CCMoveTo *move4 = CCMoveTo::create(duration, ccp(size.width-20, 20));     CCSequence *sequence = CCSequence::create(move1,move2,move3,move4,NULL);     CCRepeatForever *repeat = CCRepeatForever::create(sequence);     item->runAction(repeat);               CCLabelTTF *label = (CCLabelTTF *)this->getChildByTag(10);     CCRotateBy *rotateBy = CCRotateBy::create(8, 360);     CCMoveTo *move11 = CCMoveTo::create(2, ccp(0, size.height/2));     CCMoveTo *move13 = CCMoveTo::create(2, ccp(size.width, size.height/2));     CCMoveTo *move12 = CCMoveTo::create(2, ccp(size.width/2, size.height/2));     CCSequence *sequence1 = CCSequence::create(move11,move12,move13,move12,NULL);     CCSpawn *span = CCSpawn::create(sequence1,rotateBy,NULL);     CCRepeatForever *repeat1 = CCRepeatForever::create(span);     label->runAction(repeat1);   }

資源文件:http://download.csdn.net/detail/s10141303/6214883

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

内黄县| 龙川县| 乐清市| 湟源县| 乳源| 柏乡县| 屯昌县| 罗源县| 宁陕县| 辽宁省| 乌兰察布市| 萝北县| 滦南县| 玉山县| 亳州市| 庄浪县| 白城市| 嘉祥县| 闸北区| 陵水| 凤台县| 泾源县| 无棣县| 望都县| 望奎县| 和田市| 通化县| 奇台县| 新竹县| 手机| 舒兰市| 唐海县| 尚义县| 昌江| 西乡县| 宜兰县| 乌兰察布市| 东港市| 沁源县| 大厂| 大理市|