加载资源进度条
来源:互联网 发布:java 判断小数 编辑:程序博客网 时间:2024/04/27 14:56
在很多游戏中,控制图片的载入和释放,可以使我们的游戏更加流畅,我们使用如下的方法载入图片并且回调load函数,在屏幕上显示载入进度
CCTextureCache::sharedTextureCache()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
///////////////////////////
有时候场景中的资源加载过多的话就会引起游戏进入的时候很卡,因为那是边加载边显示。在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);
- }
0 0
- 加载资源进度条
- 资源加载进度条
- Cocos2d-x 资源加载进度条
- Cocos2dx 3.x 资源加载进度条Loading...
- Cocos2dx 3.0资源加载进度条Loading...
- 前端资源预加载并展示进度条
- 异步加载游戏场景与异步加载游戏资源进度条
- 转老孟一篇在Silverlight 2.0中制作资源加载进度条
- 在J2ME上实现平滑的资源加载进度条
- Cocos2dx 3.0 过渡篇(十)资源加载进度条Loading...
- Cocos2dx之进度条使用,异步加载资源进缓存
- Cocos2dx 3.0 过渡篇(十)资源加载进度条Loading...
- Cocos2dx 3.0 过渡篇(十)资源加载进度条Loading...
- 关于cocos2d-x进度条的实现和异步加载资源
- TangIDE开发技巧之自定义资源加载窗口进度条
- addImageAsync异步加载资源和进度条ProgressTimer的实现
- Quick-cocos2d-x 中进度条与资源加载
- Cocos2d-x 3.10 资源加载进度条Loading显示百分比
- hive统计网站指标总结
- Linux分区方案、文件结构与挂载
- 【Android】Android系统性能调优工具介绍
- Android4.X 的SIM卡信息的初始化过程
- 将excel数据通过plsql导入oracle的问题
- 加载资源进度条
- 一些资料书签(备份)
- 栈(C++实现)
- spring mvc 多视图配置
- 手机短信记录丢失如何恢复
- HTML +JavaScript 正则表达式来验证信息
- Windows 下单机最大TCP连接数
- 强制td不换行
- 快速排序算法