获取cocos2dx3.3资源文件下的文件名, 异步加载所有资源
来源:互联网 发布:淘宝 批量上架 编辑:程序博客网 时间:2024/06/05 19:33
异步加载纹理参考:<a target=_blank href="http://cn.cocos2d-x.org/tutorial/show?id=2450">http://cn.cocos2d-x.org/tutorial/show?id=2450</a>
void Loading::loadTextureCache(){//getResName;std::vector<std::string>saveFiles;
<span style="white-space:pre"></span>//获取路径std::vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths();std::string resName = "res";std::string imgPath = "general/img";std::string findPath;
//找出 resName 的路径名for (auto it : searchPathArray){if (it.find(resName) != std::string::npos){findPath = it + imgPath; // ../res/general/imgbreak;}}getFiles(findPath, saveFiles);//only support .jpg .png 只支持png和jpg格式for (auto itor = saveFiles.begin(); itor != saveFiles.end();){auto l = *itor;if (l.find(".png") != std::string::npos || l.find(".jpg") != std::string::npos){++itor;}else{itor = saveFiles.erase(itor);}}//load 异步加载所有<span style="font-family: Arial, Helvetica, sans-serif;">imgPath路径下的所有纹理</span>_numOfTexture = saveFiles.size();for (int i = 0; i < _numOfTexture; i++){size_t len = saveFiles[i].find(imgPath);std::string outPath = saveFiles[i].substr(len);//CCLOG("-------------- > %s", outPath.c_str());Director::getInstance()->getTextureCache()->addImageAsync(outPath, CC_CALLBACK_1(Loading::loadTextureCacheCallback, this));}}
//异步回调void Loading::loadTextureCacheCallback(Texture2D *texture){CCLOG("%d/%d", ++_loadedOfTexture, _numOfTexture);if (_loadedOfTexture == _numOfTexture){
<span style="white-space:pre"></span>//测试 initAllScenes() 耗时int time = clock();if (initAllScenes()){CCLOG("==============initAllScenes===================> useTime = %d", clock() - time);}else{//do sth}}}
//get full path 获取path文件下的所有文件名void Loading::getFiles(std::string path, std::vector<std::string>& files){//file handle long hFile = 0;//file info struct _finddata_t fileinfo;std::string p;if ((hFile = _findfirst(p.assign(path).append("/*").c_str(), &fileinfo)) != -1){do{//if is dir ,iteration getFiles(...); if ((fileinfo.attrib & _A_SUBDIR)){if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0){getFiles(p.assign(path).append("/").append(fileinfo.name), files);}}else{//if isn't dir, push_back vector.files.push_back(p.assign(path).append("/").append(fileinfo.name));}} while (_findnext(hFile, &fileinfo) == 0);_findclose(hFile);}}
0 0
- 获取cocos2dx3.3资源文件下的文件名, 异步加载所有资源
- Unity 获取指定资源目录下的所有文件
- Unity 获取指定资源目录下的所有文件
- 获取web应用下加载资源文件的方法
- 知道资源ID,获取资源的文件名
- android 代码加载 已知文件名 的资源文件
- Android获取drawable下所有资源文件id
- c# .Net 根据资源文件名获取资源文件对象
- 获取目录下的所有文件名、删除文件、创建文件
- Android 获取资源目录下的文件
- Java实现获取Web上所有路径下资源文件的URL地址
- C#获取文件夹下的所有文件的文件名
- C#获取文件夹下的所有文件的文件名
- C#获取文件夹下的所有文件的文件名
- C#获取文件夹下的所有文件的文件名
- yepnope.js – 异步加载资源文件
- yepnope.js 异步加载资源文件
- web下加载资源文件
- Hibernate数据查询
- 使用python解析Json字符串-获取Json字符串关键字
- iOS自动打包总结
- svn: This client is too old to work with the working...
- [正则]匹配从0到100(不包括0,包括100)的数字
- 获取cocos2dx3.3资源文件下的文件名, 异步加载所有资源
- 为32位程序 开启3G
- 夫妻箴言
- 加速编译
- 进程间通信 - 匿名管道实现
- LeakCanary: 让内存泄露无所遁形
- mac下安装ant
- GridBagLayout使用心得
- 在CSS3中制作小三角形效果代码