温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-05-30 18:24:22 来源:网络 阅读:1899 作者:破军少帅 栏目:游戏开发

cocos2dx 在多场景切换中,生命周期打印的效果如下:


从 MyScene 场景进入,切换到 HelloWorld 场景,再推出 HelloWorld 场景,流程图(见附件,,,,不知道怎么上传图片,不能粘贴图,郁闷。。。)


打印 log 如下,


MyScene 代码:
MyScene::MyScene() {
	CCLog("wangss------------->MyScene");
}
MyScene::~MyScene() {
	CCLog("wangss------------->~~MyScene");
}
void MyScene::onEnter() {
	CCLog("wangss------------->onEnter");
	Layer::onEnter();

}
void MyScene::onEnterTransitionDidFinish() {
	CCLog("wangss------------->onEnterTransitionDidFinish");
}
void MyScene::onExit() {
	CCLog("wangss------------->onExit");
	Layer::onExit();
}
void MyScene::onExitTransitionDidStart() {
	CCLog("wangss------------->onExitTransitionDidStart");
}
void MyScene::cleanup() {
	CCLog("wangss------------->cleanup");
}

Scene* MyScene::createScene() {
	CCLog("wangss------------->createScene");
	auto scene = Scene::create();
	auto layer = MyScene::create();
	scene->addChild(layer);
	return scene;
}
bool MyScene::init() {
	CCLog("wangss------------->init");
	if (!Layer::init()) {
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = 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);
	return true;
}


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' is an autorelease object
    auto scene = Scene::create();
    
    // 'layer' is an autorelease object
    auto layer = HelloWorld::create();

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}

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




附件:http://down.51cto.com/data/2365029
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI