//// HelloWorldScene.h//#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"#include "cocos-ext.h"#include "TestLayer.h"USING_NS_CC;USING_NS_CC_EXT;class HelloWorld : public cocos2d::cclayer{public: virtual bool init(); static cocos2d::CCScene* scene(); CREATE_FUNC(HelloWorld); voID changeScene(); // CCNode生命周期函数 virtual voID onEnter(); virtual voID onEnterTransitionDIDFinish(); virtual voID onExit(); // 解释上面3个生命周期函数 /* virtual voID onEnter(); 当init()函数执行完成后,默认进入onEnter()生命周期函数 virtual voID onEnterTransitionDIDFinish(); 当A场景切换到B场景时,过度动画执行完成后默认调用B场景的onEnterTransitionDIDFinish()生命周期函数 virtual voID onExit(); 当场景退出后,默认调用此生命周期函数 */ // A场景和B场景切换时的生命周期函数调用顺序如下: /* 1、B场景的init函数 2、B场景的OnEnter函数 3、A场景的OnExit函数 4、B场景的onEnterTransitionDIDFinish函数 5、A场景的析构函数 */};#endif
//// HelloWorldScene.cpp//#include "HelloWorldScene.h"USING_NS_CC;CCScene* HelloWorld::scene(){ CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene;}bool HelloWorld::init(){ if ( !cclayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *pSpr = CCSprite::create("background1.png"); pSpr->setposition(ccp(240,160)); addChild(pSpr); cclabelTTF *labelTTF =cclabelTTF::create("点击切换场景","Helvetica-Hald",30); labelTTF->setcolor(ccRED); CcmenuItemLabel *labelitem = CcmenuItemLabel::create(labelTTF,this,menu_selector(HelloWorld::changeScene)); Ccmenu *menu = Ccmenu::create(labelitem,NulL); addChild(menu); return true;}voID HelloWorld::changeScene(){ CCTransitionScene *reScene = NulL; CCScene *s = TestLayer::scene(); float t = 1.2f; // CCTransitionJumpZoom reScene = CCTransitionJumpZoom::create(t,s); // CCTransitionProgressRadialccw reScene = CCTransitionProgressRadialccw::create(t,s); // CCTransitionProgressRadialCW /*reScene = CCTransitionProgressRadialCW::create(t,s); // CCTransitionProgressHorizontal reScene = CCTransitionProgressHorizontal::create(t,s); // CCTransitionProgressvertical reScene = CCTransitionProgressvertical::create(t,s); // CCTransitionProgressInOut reScene = CCTransitionProgressInOut::create(t,s); // CCTransitionProgressOutIn reScene = CCTransitionProgressOutIn::create(t,s); // CCTransitionCrossFade reScene = CCTransitionCrossFade::create(t,s); // CCTransitionPageTurn reScene = CCTransitionPageTurn::create(t,s,false); // CCTransitionFadeTR reScene = CCTransitionFadeTR::create(t,s); // CCTransitionFadeBL reScene = CCTransitionFadeBL::create(t,s); // CCTransitionFadeUp reScene = CCTransitionFadeUp::create(t,s); // CCTransitionFadeDown reScene = CCTransitionFadeDown::create(t,s); // CCTransitionTurnOffTiles reScene = CCTransitionTurnOffTiles::create(t,s); // CCTransitionSplitRows reScene = CCTransitionSplitRows::create(t,s); // CCTransitionSplitCols reScene = CCTransitionSplitCols::create(t,s); // CCTransitionFade reScene = CCTransitionFade::create(t,ccRED); // CCTransitionFlipX reScene = CCTransitionFlipX::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionFlipY reScene = CCTransitionFlipY::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionFlipAngular reScene = CCTransitionFlipAngular::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionZoomFlipX reScene = CCTransitionZoomFlipX::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionZoomFlipY reScene = CCTransitionZoomFlipY::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionZoomFlipAngular reScene = CCTransitionZoomFlipAngular::create(t,kCCTransitionOrIEntationleftOver); // CCTransitionShrinkGrow reScene = CCTransitionShrinkGrow::create(t,s); // CCTransitionRotoZoom reScene = CCTransitionRotoZoom::create(t,s); // CCTransitionMoveInL reScene = CCTransitionMoveInL::create(t,s); // CCTransitionMoveInR reScene = CCTransitionMoveInR::create(t,s); // CCTransitionMoveInT reScene = CCTransitionMoveInT::create(t,s); // CCTransitionMoveInB reScene = CCTransitionMoveInB::create(t,s); // CCTransitionSlIDeInL reScene = CCTransitionSlIDeInL::create(t,s); // CCTransitionSlIDeInR reScene = CCTransitionSlIDeInR::create(t,s); // CCTransitionSlIDeInT reScene = CCTransitionSlIDeInT::create(t,s); // CCTransitionSlIDeInB reScene = CCTransitionSlIDeInB::create(t,s);*/ CCDirector::sharedDirector()->replaceScene(reScene);}voID HelloWorld::onEnter(){ cclayer::onEnter(); // 务必调用 cclOG("HelloWorld::onEnter");}voID HelloWorld::onEnterTransitionDIDFinish(){ cclayer::onEnterTransitionDIDFinish(); // 务必调用 cclOG("HelloWorld::onEnterTransitionDIDFinish");}voID HelloWorld::onExit(){ cclayer::onExit(); cclOG("HelloWorld::onExit");}
//// TestLayer.h// #ifndef HelloWorld_TestLayer_h#define HelloWorld_TestLayer_h#include "cocos2d.h"#include "cocos-ext.h"USING_NS_CC;USING_NS_CC_EXT;class TestLayer : public cocos2d::cclayer{public: virtual bool init(); static cocos2d::CCScene *scene(); CREATE_FUNC(TestLayer); // CCNode生命周期函数 virtual voID onEnter(); virtual voID onEnterTransitionDIDFinish(); virtual voID onExit();};#endif
//// TestLayer.cpp//#include "TestLayer.h"USING_NS_CC;CCScene *TestLayer::scene(){ CCScene *scene = CCScene::create(); TestLayer *layer = TestLayer::create(); scene->addChild(layer); return scene;}bool TestLayer::init(){ if (!cclayer::init()) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *pSpr = CCSprite::create("background2.png"); pSpr->setposition(ccp(winSize.wIDth*0.5,winSize.height*0.5)); this->addChild(pSpr); return true;}voID TestLayer::onEnter(){ cclayer::onEnter(); cclOG("TestLayer::onEnter");}voID TestLayer::onEnterTransitionDIDFinish(){ cclayer::onEnterTransitionDIDFinish(); cclOG("TestLayer::onEnterTransitionDIDFinish");}voID TestLayer::onExit(){ cclayer::onExit(); cclOG("TestLayer::onExit");}总结
以上是内存溢出为你收集整理的Cocos2d-x_场景切换常用特效和CCNode的生命周期函数全部内容,希望文章能够帮你解决Cocos2d-x_场景切换常用特效和CCNode的生命周期函数所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)