cocos2dx3.3开发FlappyBird总结八:载入场景LoadingScene
来源:互联网 发布:手机音乐软件 编辑:程序博客网 时间:2024/06/05 04:49
载入场景的目的是预加载资源,也就是在场景进入时,把资源加载到内存中:
// 重写onEnter方法,场景载入时,会调用此方法,此外我们还需要调一下父类的方法,这个是API说明的,照做就行。// 方法其实功能是很简单的,就是先显示一张splash图片,然后异步加载图片资源,这个addImageAsync方法是引擎内部提供的API,可异步加载,这样就不会阻塞主线程了。void LoadingScene::onEnter() { Layer::onEnter(); // Add the splash screen image auto background = Sprite::create("splash.png"); auto size = Director::getInstance()->getVisibleSize(); auto origin = Director::getInstance()->getVisibleOrigin(); background->setPosition(origin.x + size.width / 2, origin.y + size.height / 2); this->addChild(background); // Start to load texture async auto texture = Director::getInstance()->getTextureCache(); texture->addImageAsync("atlas.png", CC_CALLBACK_1(LoadingScene::onLoadFinishedCallback, this));}
加载完成后,就是加载音频文件,这里是同步加载的,如果资源很多的话,会卡的。加载完成后,就进入到WelcomeScene了。
void LoadingScene::onLoadFinishedCallback(cocos2d::Texture2D *texture) { // Load the atlas AtlasLoader::getInstance()->loadAtlas("atlas.txt", texture); // Preload effect music. // Here is not the best way to load all music files, // in real projects, you should find a better way to do. CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sfx_die.ogg"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sfx_hit.ogg"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sfx_point.ogg"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sfx_swooshing.ogg"); CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("sfx_wing.ogg"); // Now the task of the loading scene has finished, // auto enter into the welcome scene auto scene = TransitionFade::create(1.0f, WelcomeScene::createScene()); Director::getInstance()->replaceScene(scene);}
下一步:说说欢迎场景
0 0
- cocos2dx3.3开发FlappyBird总结八:载入场景LoadingScene
- cocos2dx3.3开发FlappyBird总结九:欢迎场景(WelcomeScene)
- cocos2dx3.3开发FlappyBird总结十七:结束语
- FlappyBird开发总结(八)——MainScene场景
- cocos2dx3.3开发FlappyBird总结一:背景介绍
- cocos2dx3.3开发FlappyBird总结三:项目剖析
- cocos2dx3.3开发FlappyBird总结四:资源管理类
- cocos2dx3.3开发FlappyBird总结五:说说屏幕适配
- cocos2dx3.3开发FlappyBird总结七:说说游戏流程
- cocos2dx3.3开发FlappyBird总结十:背景层设计
- cocos2dx3.3开发FlappyBird总结十一:控制层功能设计
- cocos2dx3.3开发FlappyBird总结十二:状态层设计
- cocos2dx3.3开发FlappyBird总结十三:数字特效类
- cocos2dx3.3开发FlappyBird总结十四:常量定义
- cocos2dx3.3开发FlappyBird总结十五:记录玩家得分
- cocos2dx3.3开发FlappyBird总结十六:游戏层实现
- cocos2dx3.3开发FlappyBird总结六:设计共享小鸟类(主角)
- FlappyBird开发总结(二)——场景
- json.dump() and sorted() dict
- cocos2dx 工程运行时 发生访问冲突 有可能是消息未移除的原因
- 高仿微信5.2.1主界面架构 包含消息通知
- [Help] Syncfusion.XlsIO componet 's bug in open "xlsx"file.
- poj1189 简单dp
- cocos2dx3.3开发FlappyBird总结八:载入场景LoadingScene
- 如何查看linux发行版版本信息
- iGrimace OpenSSH的安装
- ScheduledExecutorService 根据条件终止调度任务
- material design UI 色版
- python学习之--安装配置环境
- 使用model(MVC模式)在iOS开发中的重要性.
- dubbo 学习
- 开源日志系统 log4c 使用心得+总结