cocos2d-x Loading界面实现资源加载
来源:互联网 发布:linux常用软件包 编辑:程序博客网 时间:2024/06/08 19:57
有时候场景中的资源加载过多的话就会引起游戏进入的时候很卡,因为那是边加载边显示。在tests例子里面有一个很好的例子叫做TextureCacheTest,里面讲解了如何写loading。
- #include "LoadingScene.h"
- #include "HelloWorldScene.h"
- bool LoadingScene::init()
- {
- totalNum=9; //记录总的加载数量
- haveLoadedNum=0; //记录已加载的数量
- this->loading();
- return true;
- }
- CCScene *LoadingScene::scene()
- {
- CCScene *scene=CCScene::create();
- LoadingScene *layer=LoadingScene::create();
- scene->addChild(layer);
- return scene;
- }
- void LoadingScene::loading()
- {
- CCSize size=CCDirector::sharedDirector()->getWinSize();
- ttf=CCLabelTTF::create("%0", "Arial", 12); //显示加载进度
- CCLabelTTF *havettf=CCLabelTTF::create("Loading", "Arial", 12);
- this->addChild(ttf,1);
- this->addChild(havettf,1);
- ttf->setPosition(ccp(size.width/3, size.height/2));
- havettf->setPosition(ccp(size.width/2, size.height/2));
- CCTextureCache::sharedTextureCache()->addImageAsync("youlost.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("youwin.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("cat.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catBody1.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catBody2-4.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catBody3.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catHand1.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catHand2.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- CCTextureCache::sharedTextureCache()->addImageAsync("catTail.png", this, callfuncO_selector(LoadingScene::loadedCallBack));
- }
- void LoadingScene::loadedCallBack()
- {
- haveLoadedNum++;
- this->runAction(CCDelayTime::create(15));
- char tmp[10];
- sprintf(tmp, "%%%d",(int)((float)haveLoadedNum/totalNum*100));
- ttf->setString(tmp); //更改加载进度
- if (haveLoadedNum==9)
- {
- this->removeChild(ttf, true); //加载完成后,移除加载进度显示
- CCScene *newscne=HelloWorld::scene();
- CCDirector::sharedDirector()->replaceScene(newscne); //场景切换
- }
- }
- bool HelloWorld::init()
- {
- if ( !CCLayer::init() )
- {
- return false;
- }
- CCSprite *sp=CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->textureForKey("youlost.png"));
- addChild(sp,1);
- }
欢迎转载,转载请注明出处:http://blog.csdn.net/somestill/article/details/10258519
1 0
- Cocos2d-x--实现Loading界面加载资源
- cocos2d-x Loading界面实现资源加载
- Cocos2d-x--实现Loading界面加载资源
- cocos2d-x Loading界面实现资源加载
- cocos2d-x v3.2 Loading界面实现资源加载
- Cocos2d-x 3.x 异步加载资源和Loading界面
- Cocos2d-x 实现Loading界面加载资源进度条显示百分比(回调函数)
- cocos2d-x 3.6版loading加载资源
- cocos2d-x 3.0 Loading界面实现
- Cocos2d-x 3.2 游戏资源Loading界面简单Demo
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- cocos2d-x游戏开发(十五)游戏加载动画loading界面
- Cocos2d-x 3.10 资源加载进度条Loading显示百分比
- cocos2d-x - loading加载动画
- [Cocos2d-x] loading加载动画
- 【Cocos2d-html5游戏引擎学习笔记(6)】自定义Cocos2d-html5加载资源Loading界面
- cocos2d-x 3.3 之卡牌设计 NO.6 Loading界面(异步加载图片,plist)
- YTU 2558: 游起来吧!超妹!
- docker(二):构建镜像
- Python教程学习简记6--Python 生成器 generator
- YTU 2559: “心脏出血”
- viewpager立方体切换效果
- cocos2d-x Loading界面实现资源加载
- 高并发的核心技术-幂等的实现方案
- 5.Xib和storyboard对比
- 【Linux相关】linux大文件分割与合并
- YTU 2562: 黄金螺旋
- poj 1703 Find them, Catch them(Dsu)
- spark源码学习(二)---Master源码分析(2)-master内组件状态改变机制
- destoon的重新安装
- NGINX301 REWRITE官方博客文档