加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx Scene 生命周期(replaceScene,popScene后续补充)

发布时间:2020-12-14 19:18:33 所属栏目:百科 来源:网络整理
导读:cocos2dx 在多场景切换中,生命周期打印的效果如下: 从 MyScene 场景进入,切换到 HelloWorld 场景,再推出 HelloWorld 场景,流程图(见附件,,,,不知道怎么上传图片,不能粘贴图,郁闷。。。) 打印 log 如下, MyScene代码:MyScene::MyScene(){CCLog

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读