日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區(qū)平臺 聯系我們 | 收藏本站
阿里云優(yōu)惠2
您當前位置:首頁 > 互聯網 > 場景切換

場景切換

來源:程序員人生   發(fā)布時間:2014-10-03 08:00:01 閱讀次數:1911次

實現場景轉換需要通過場景函數實現,場景函數有:

runWithScene:運行場景

runWithScene屬于CCDirector類的成員函數

函數原型: void runWithScene(CCScene *pScene)

函數參數: *pScene(CCScene型指針)


replaceScene:切換場景

replaceScene屬于CCDirector類的成員函數

函數原型: void replaceScene(CCScene *pScene);

函數參數: *pScene(CCScene型指針)


pushScene: 將場景壓到棧中

pushScene屬于CCDirector類的成員函數

函數原型:void pushScene(CCScene *pScene);

函數參數: *pScene(CCScene型指針)


popScene :彈出棧中的場景

popScene屬于CCDirector類的成員函數

函數原型:void popScene(void);

函數參數: 沒有參數


pause: 暫停場景

pause屬于CCDirector類的成員函數

函數原型:void pause(void)

函數參數: 沒有參數


resume:繼續(xù)運行場景

resume屬于CCDirector類的成員函數

函數原型:void resume(void)

函數參數: 沒有參數


end: 結束場景

end屬于CCDirector類的成員函數

函數原型:void end(void)

函數參數: 沒有參數


建立工程測試場景函數:

建立一個SceneMan工程,在工程中添加一個SceneSecond類

在SceneSecond.h文件中添加下面的代碼

#ifndef _SenceSecond_H_ #define _SenceSecond_H_ //防止代碼重包含 #include "cocos2d.h" USING_NS_CC; class SceneSecond : public CCLayer { public: //創(chuàng)建一個場景 static CCScene* scene(); //初始化場景 bool init(); //菜單回調函數 void menuCloseCallback(CCObject* pSender); CREATE_FUNC(SceneSecond); }; #endif

在SeceneSecond.cpp中添加下面的代碼

#include "SceneSecond.h" #include "HelloWorldScene.h" CCScene* SceneSecond::scene() { //創(chuàng)建一個場景 CCScene* s = CCScene::create(); //創(chuàng)建一個layer SceneSecond* layer = SceneSecond::create(); //將layer加到場景中 s->addChild(layer); //返回CCScene指針 return s; } bool SceneSecond::init() { //先調用父類的init函數 CCLayer::init(); //在場景中顯示文字 CCLabelTTF *label = CCLabelTTF::create("SceneSecond", "abcde", 36); //設置顯示文字的位置(坐標) label->setPosition(CCPoint(100,200)); //將文字加到場景中 addChild(label); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(SceneSecond::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); //創(chuàng)建一個菜單 CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); return true; } //菜單回調函數 void SceneSecond::menuCloseCallback(CCObject* pSender) { //切換到HelloWorld場景 CCDirector::sharedDirector()->popScene(); }

最后將HelloWorld.cpp文件中的代碼修改成

#include "HelloWorldScene.h" #include "SceneSecond.h" USING_NS_CC; 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; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 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(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); static int i = 1; char buf[256]; sprintf(buf, "Hello World %d", i++); CCLabelTTF* pLabel = CCLabelTTF::create(buf, "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.png"); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(pSprite, 0); return true; } //點擊按鈕后調用的函數 void HelloWorld::menuCloseCallback(CCObject* pSender) { //切換到SceneSecond場景 CCDirector::sharedDirector()->pushScene(SceneSecond::scene()); }

編譯程序:程序的執(zhí)行結果為



修改程序代碼,將SceneSecond.cpp中的void SceneSecond::menuCloseCallback(CCObject* pSender)函數中的代碼

CCDirector::sharedDirector()->popScene();

修改成

CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());


將HelloWorldScene.cpp中void HelloWorld::menuCloseCallback(CCObject* pSender)函數中的代碼

CCDirector::sharedDirector()->pushScene(SceneSecond::scene());

修改成

CCDirector::sharedDirector()->replaceScene(SceneSecond::scene());

程序執(zhí)行結果:




修改后HelloWorld后的數字會出現累加,是因為在上一個程序中使用的場景切換函數為棧函數,在切換場景的過程中會執(zhí)行出棧和壓棧操作,不會出現累加,而使用replace函數切換場景的時候會實現數據累加



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 男操女视频网站 | 国产精品尤物视频 | 国产精品99久久久久久动医院 | 国产精品久久毛片av大全日韩 | 精品天堂| 欧美一区二区三区 | 亚洲免费高清 | 91久久精品国产 | 免费黄色在线 | 欧美日韩在线免费 | 欧美成人三区 | 亚洲精品综合 | 99久久精品免费看国产免费软件 | 欧美最猛性xxxx | 久久免费一区 | 日韩成人美女视频 | v天堂福利视频在线观看 | 久久精品在线视频 | 亚洲成人一区在线观看 | 亚洲精品国产综合99久久夜夜嗨 | 欧美专区亚洲专区 | 午夜精品久久久久久久96蜜桃 | 国产91亚洲精品一区二区三区 | 久艹福利| 久草手机在线观看 | 久久国产精品影视 | 国产精品99久久 | av在线成人| 国产综合网站 | 岛国一区| 成人久久久 | 精品视频久久久久久 | 欧美日韩国产三区 | 免费a级黄毛片 | 久草在线观看首页 | 国产成人高清精品免费5388 | 成人av观看 | 国产在线小视频 | 91网站链接 | 一级aaa级毛片午夜在线播放 | 91日韩在线 |