【cocos2dx】如何实现场景的跳转

【cocos2dx】如何实现场景的跳转,第1张

概述前面定义了一个SpalshScene.h,并声明了如下的函数,在SplashScene.cpp中对这些函数实现, 跳转用到了CCNode类的定时器有关的函数,详细参考书,这里采用的函数为: void scheduleOnce(SEL_SCHEDULE selector, float delay)// 启动一次定时器,参数为回调函数及延时启动时间 #include "SplashScene.h"


前面定义了一个SpalshScene.h,并声明了如下的函数,在SplashScene.cpp中对这些函数实现,

跳转用到了CCNode类的定时器有关的函数,详细参考书,这里采用的函数为:

voID scheduleOnce(SEL_SCHEDulE selector,float delay)// 启动一次定时器,参数为回调函数及延时启动时间

#include "SplashScene.h"bool Splash::init(){	if (!Layer::init()){		return false;	}	// show game name 	auto labelGame = Label::createWithBMFont("futura-48.fnt","2048");	labelGame->setposition(Point(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT/2));	this->addChild(labelGame);	labelGame->setScale(1.5);	//show game studio	auto labelGameVec = Label::createWithBMFont("futura-48.fnt","ml_studio");	labelGameVec->setposition(Point(GAME_SCREEN_WIDTH / 2,GAME_SCREEN_HEIGHT / 4));	this->addChild(labelGameVec);	labelGameVec->setScale(0.8);	//计划任务。3秒钟之后自动跳转到游戏场景。	this->scheduleOnce(schedule_selector(Splash::jumpToGame),1);// wait one second	// jumpToGame(float) 在下面定义了	return  true;}Scene * Splash::createScene(){	auto scene = Scene::create();	auto layer = Splash::create();	scene->addChild(layer);	return scene;}voID Splash::jumpToGame(float t)//回调函数在这里{	auto scene = Game::createScene(); // Game is another Layer in 'GameScene.h'	Director::getInstance()->replaceScene(TransitionProgressOutIn::create(0.5,scene));}
总结

以上是内存溢出为你收集整理的【cocos2dx】如何实现场景的跳转全部内容,希望文章能够帮你解决【cocos2dx】如何实现场景的跳转所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1026316.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存