cocos2dx 在多场景切换中,生命周期打印的效果如下:
从 MyScene 场景进入,切换到 HelloWorld 场景,再推出 HelloWorld 场景,流程图(见附件,,,,不知道怎么上传图片,不能粘贴图,郁闷。。。)
打印 log 如下,
MyScene代码: MyScene::MyScene(){ CCLog("wangss------------->MyScene"); } MyScene::~MyScene(){ CCLog("wangss------------->~~MyScene"); } voidMyScene::onEnter(){ CCLog("wangss------------->onEnter"); Layer::onEnter(); } voidMyScene::onEnterTransitionDidFinish(){ CCLog("wangss------------->onEnterTransitionDidFinish"); } voidMyScene::onExit(){ CCLog("wangss------------->onExit"); Layer::onExit(); } voidMyScene::onExitTransitionDidStart(){ CCLog("wangss------------->onExitTransitionDidStart"); } voidMyScene::cleanup(){ CCLog("wangss------------->cleanup"); } Scene*MyScene::createScene(){ CCLog("wangss------------->createScene"); autoscene=Scene::create(); autolayer=MyScene::create(); scene->addChild(layer); returnscene; } boolMyScene::init(){ CCLog("wangss------------->init"); if(!Layer::init()){ returnfalse; } SizevisibleSize=Director::getInstance()->getVisibleSize(); Vec2origin=Director::getInstance()->getVisibleOrigin(); //spriteTest(visibleSize); //labelTest(visibleSize); //menuTest(visibleSize); //languageTest(visibleSize); //scheduleTest(visibleSize); //scaleNineSpriteTest(visibleSize); //shujujiegouTest(visibleSize); //actionTest(visibleSize); //actionCallBackTest(visibleSize); //frameAnimationTest(visibleSize); //actionEaseTest(visibleSize); //progressActionTest(visibleSize); lifeCycleTest(visibleSize); returntrue; } HelloWorld代码: HelloWorld::HelloWorld(){ CCLog("wangss------HelloWorld------->HelloWorld"); } HelloWorld::~HelloWorld(){ CCLog("wangss------HelloWorld------->~~HelloWorld"); } voidHelloWorld::onEnter(){ CCLog("wangss------HelloWorld------->onEnter"); Layer::onEnter(); } voidHelloWorld::onEnterTransitionDidFinish(){ CCLog("wangss------HelloWorld------->onEnterTransitionDidFinish"); } voidHelloWorld::onExit(){ CCLog("wangss------HelloWorld------->onExit"); Layer::onExit(); } voidHelloWorld::onExitTransitionDidStart(){ CCLog("wangss------HelloWorld------->onExitTransitionDidStart"); } voidHelloWorld::cleanup(){ CCLog("wangss------HelloWorld------->cleanup"); } Scene*HelloWorld::createScene() { CCLog("wangss------HelloWorld------->createScene"); //'scene'isanautoreleaSEObject autoscene=Scene::create(); //'layer'isanautoreleaSEObject autolayer=HelloWorld::create(); //addlayerasachildtoscene scene->addChild(layer); //returnthescene returnscene; }
11-02 15:09:40.290: D/cocos2d-x debug info(23066): wangss------------->createScene
11-02 15:09:40.300: D/cocos2d-x debug info(23066): wangss------------->MyScene
11-02 15:09:40.300: D/cocos2d-x debug info(23066): wangss------------->init
11-02 15:09:40.320: D/cocos2d-x debug info(23066): wangss------------->onEnter
11-02 15:09:40.320: D/cocos2d-x debug info(23066): wangss------------->onEnterTransitionDidFinish
11-02 15:09:43.640: D/cocos2d-x debug info(23066): wangss------HelloWorld------->createScene
11-02 15:09:43.640: D/cocos2d-x debug info(23066): wangss------HelloWorld------->HelloWorld
11-02 15:09:43.640: D/cocos2d-x debug info(23066): wangss------HelloWorld------->init
11-02 15:09:43.760: D/cocos2d-x debug info(23066): wangss------------->onExitTransitionDidStart
11-02 15:09:43.760: D/cocos2d-x debug info(23066): wangss------HelloWorld------->onEnter
11-02 15:09:44.940: D/cocos2d-x debug info(23066): wangss------------->onExit
11-02 15:09:44.940: D/cocos2d-x debug info(23066): wangss------HelloWorld------->onEnterTransitionDidFinish
11-02 15:09:44.940: D/cocos2d-x debug info(23066): wangss------------->cleanup
11-02 15:09:44.940: D/cocos2d-x debug info(23066): wangss------------->~~MyScene
11-02 15:09:46.220: D/cocos2d-x debug info(23066): wangss------HelloWorld------->onExit
11-02 15:09:46.220: D/cocos2d-x debug info(23066): wangss------HelloWorld------->cleanup
11-02 15:09:46.220: D/cocos2d-x debug info(23066): wangss------HelloWorld------->~~HelloWorld
原文链接:https://www.f2er.com/cocos2dx/346470.html