大佬教程收集整理的这篇文章主要介绍了cocos2dx Scene 生命周期(replaceScene,popScene后续补充),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
cocos2dx 在多场景切换中,生命周期打印的效果如下:
从 MyScene 场景进入,切换到 HelloWorld 场景,再推出 HelloWorld 场景,流程图(见附件,,,,不知道怎么上传图片,不能粘贴图,郁闷。。。)
打印 log 如下,
@H_246_15
@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())
{
return
false;
}
SizevisibleSize=Director::ge
Tinstance()->getVisibleSize(
);
Vec2origin=Director::ge
Tinstance()->getVisib
Leorigin(
);
//spriteTest(visibleSiz
E);
//labelTest(visibleSiz
E);
//menuTest(visibleSiz
E);
//languageTest(visibleSiz
E);
//
scheduleTest(visibleSiz
E);
//scaleNi
nespriteTest(visibleSiz
E);
//shujujiegouTest(visibleSiz
E);
//actionTest(visibleSiz
E);
//actionCall
BACkTest(visibleSiz
E);
//frameAnimationTest(visibleSiz
E);
//actionEaseTest(visibleSiz
E);
//progressActionTest(visibleSiz
E);
lifeCycleTest(visibleSiz
E);
returntrue;
}
HelloWorld
代码:
HelloWorld::
HelloWorld()
{
CCLog("wangss------
HelloWorld------->
HelloWorld"
);
}
HelloWorld::~
HelloWorld()
{
CCLog("wangss------
HelloWorld------->~~
HelloWorld"
);
}
void
HelloWorld::onEnter()
{
CCLog("wangss------
HelloWorld------->onEnter"
);
Layer::onEnter(
);
}
void
HelloWorld::onEnterTransitionDidFinish()
{
CCLog("wangss------
HelloWorld------->onEnterTransitionDidFinish"
);
}
void
HelloWorld::onExit()
{
CCLog("wangss------
HelloWorld------->onExit"
);
Layer::onExit(
);
}
void
HelloWorld::onExitTransitionDidStart()
{
CCLog("wangss------
HelloWorld------->onExitTransitionDidStart"
);
}
void
HelloWorld::cleanup()
{
CCLog("wangss------
HelloWorld------->cleanup"
);
}
Scene*
HelloWorld::createScene()
{
CCLog("wangss------
HelloWorld------->createScene"
);
//'scene'isanautoreleaseob
ject
autoscene=Scene::create(
);
//'layer'isanautoreleaseob
ject
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
大佬总结
以上是大佬教程为你收集整理的cocos2dx Scene 生命周期(replaceScene,popScene后续补充)全部内容,希望文章能够帮你解决cocos2dx Scene 生命周期(replaceScene,popScene后续补充)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。