cocos2d-x关于home键黑屏和游戏loading界面
来源:互联网 发布:千千静听软件 编辑:程序博客网 时间:2024/04/26 22:50
有时候场景中的资源加载过多的话就会引起游戏进入的时候很卡,因为那是边加载边显示。还有在游戏中按下home键 再进入游戏的时候会有一段时间的黑屏,那是因为游戏要重新加载资源,这样用户体验非常不好。
我在tests例子里面发现一个很好的例子叫做TextureCacheTest,里面讲解了如何写loading。
首先在类头文件里面写上:
//loading......callbackvoid loadingCallBack(cocos2d::CCObject *obj);void addSprite();cocos2d::CCLabelTTF *m_pLabelLoading;cocos2d::CCLabelTTF *m_pLabelPercent;int m_nNumberOfSprites;//计数用 在构造函数中初始化成要加载的资源个数int m_nNumberOfLoadedSprites;//初始化为0然后在cpp里面实现:这是我随便截取的代码
CCSize size = CCDirector::sharedDirector()->getWinSize();////////////////////////////////////////////////////////////////////////////loading界面m_pLabelLoading = CCLabelTTF::create("loading...", "Arial", 15);m_pLabelPercent = CCLabelTTF::create("%0", "Arial", 15);m_pLabelLoading->setPosition(CCPointMake(size.width / 2, size.height / 2 - 20));m_pLabelPercent->setPosition(CCPointMake(size.width / 2, size.height / 2 + 20));this->addChild(m_pLabelLoading,10);this->addChild(m_pLabelPercent,10);//////////////////////////////////////////////////////////////////////////CCTextureCache::sharedTextureCache()->addImageAsync("gobacknormal.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("gobackselected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/achievementnormal.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/achievementselected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle1normal.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle2normal.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle3normal.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle1selected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle2selected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle3selected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle1lock.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle2lock.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle3lock.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle2lockselected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/Bighurdle3lockselected.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Bighurdle/main.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));CCTextureCache::sharedTextureCache()->addImageAsync("Smallhurdle/starfull.png", this, callfuncO_selector(BighurdleLayer::loadingCallBack));然后在回调函数
void BighurdleLayer::loadingCallBack(cocos2d::CCObject *obj){++m_nNumberOfLoadedSprites;char tmp[10];sprintf(tmp,"%%%d", (int)(((float)m_nNumberOfLoadedSprites / m_nNumberOfSprites) * 100));m_pLabelPercent->setString(tmp);if (m_nNumberOfLoadedSprites == m_nNumberOfSprites){this->removeChild(m_pLabelLoading, true);this->removeChild(m_pLabelPercent, true);addSprite();//这里是自己写得添加精灵的函数}}如果有更好的方法,请告知我,谢谢 共同进步
二.当按home键到桌面去,然后回到游戏弹出个进度条 然后游戏开始
我们只需要在AppDelegate.cpp里面添加layer就可以了 然后layer里面弄上定时器 一段时间后自动取消
// this function will be called when the app is active againvoid AppDelegate::applicationWillEnterForeground(){CCSize winSize = CCDirector::sharedDirector()->getWinSize();Loading *loading = new Loading();//CCSprite *sp = CCSprite::create("HelloWorld.png");//sp->setPosition(ccp(winSize.width/2, winSize.height/2));//loading->addChild(sp);CCDirector::sharedDirector()->getRunningScene()->addChild((CCNode *)loading);
- cocos2d-x关于home键黑屏和游戏loading界面
- cocos2d-x 关于home键黑屏和游戏loading界面
- cocos2d-x 关于home键黑屏和游戏loading界面
- cocos2d-x 实现按Home和待机键后,再进入游戏显示暂停界面
- cocos2d-x 实现按Home和待机键后,再进入游戏显示暂停界面
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- Cocos2d-x 3.2 游戏资源Loading界面简单Demo
- cocos2d-x(quick--cocos2d-x)引擎开发的游戏在android平台上,锁屏,按HOME键,重反游戏后黑屏问题
- Cocos2d-x 3.x 异步加载资源和Loading界面
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x 游戏暂停界面,监听home键,返回键,Menu键 解决方案
- cocos2d-x Android游戏黑屏解决办法
- Ubuntu12.04下安装eclipse
- Web前端开发技术
- Ubuntu下配置Intellij的Android开发环境
- 链表倒置
- HDU-1394 Minimum Inversion Number 线段树|树状数组
- cocos2d-x关于home键黑屏和游戏loading界面
- 在VS2010下运行Qt程序
- C++的一些基本问题
- 提高VS2010运行速度的技巧
- 机房收费系统角色分析
- 经典好题!杭电OJ--Ignatius and the Princess I
- Java 之 访问限制:由于对必需的库 C:\Program Files\Java\jre6\lib\ext\j3dutils.jar具有一定限制,因此无法访问类型 Scene
- Building Coder(Revit 二次开发) - 真实世界中的角坐标
- 《妙趣横生的算法》第10章 算法设计与数据结构面试精粹之常见的算法设计题10-6(question?)