cocos2d 3.x 纹理缓存
来源:互联网 发布:淘宝兼职怎么做视频教程 编辑:程序博客网 时间:2024/05/19 05:02
官方的开发文档就是坑
http://cn.cocos2d-x.org/article/index?type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v2/memory/texture-cache/zh.md
就不能提供个版本号?
3.x中纹理缓存的实列获取改为了
Director::getInstance()->getTextureCache()
Director头文件中把TextureCache当成了一个保护成员变量
//texture cache belongs to this director
TextureCache *_textureCache;
Director关于TextureCache的函数有四个
<span style="color:#330000;">TextureCache* Director::getTextureCache() const{ return _textureCache;//返回TextureCache实列对象}void Director::initTextureCache()//这个是初始化TextureCache,在Director::init()里调用{#ifdef EMSCRIPTEN _textureCache = new (std::nothrow) TextureCacheEmscripten();#else _textureCache = new (std::nothrow) TextureCache();#endif // EMSCRIPTEN}void Director::destroyTextureCache()//这个应该是销毁函数,在purgeDirector()里调用,我感觉怎么是向线程的延时,没看太懂{ //purgeDirector()是在DisplayLinkDirector里调用,这个类继承于Director if (_textureCache) { _textureCache->waitForQuit(); CC_SAFE_RELEASE_NULL(_textureCache); }}void Director::purgeCachedData(void)//这个是清空无用的缓存{ FontFNT::purgeCachedData();//1 FontAtlasCache::purgeCachedData();//2 if (s_SharedDirector->getOpenGLView()) { SpriteFrameCache::getInstance()->removeUnusedSpriteFrames();//3 _textureCache->removeUnusedTextures();//4 // Note: some tests such as ActionsTest are leaking refcounted textures // There should be no test textures left in the cache log("%s\n", _textureCache->getCachedTextureInfo().c_str()); } FileUtils::getInstance()->purgeCachedEntries();//5}</span>真正用到的应该是Director::getInstance()->getTextureCache()
关于TextureCache类的方法
<span style="color:#660000;">void TextureCache::addImageAsync(const std::string &path, const std::function<void(Texture2D*)>& callback)//异步加载方式,第一个是文件路径,第二个是回调函数{ Texture2D *texture = nullptr; std::string fullpath = FileUtils::getInstance()->fullPathForFilename(path); auto it = _textures.find(fullpath); if( it != _textures.end() ) texture = it->second; if (texture != nullptr) { callback(texture); return; } // lazy init if (_asyncStructQueue == nullptr) { _asyncStructQueue = new queue<AsyncStruct*>(); _imageInfoQueue = new deque<ImageInfo*>(); // create a new thread to load images _loadingThread = new std::thread(&TextureCache::loadImage, this); _needQuit = false; } if (0 == _asyncRefCount) { Director::getInstance()->getScheduler()->schedule(CC_SCHEDULE_SELECTOR(TextureCache::addImageAsyncCallBack), this, 0, false); } ++_asyncRefCount; // generate async struct AsyncStruct *data = new (std::nothrow) AsyncStruct(fullpath, callback); // add async struct into queue _asyncStructQueueMutex.lock(); _asyncStructQueue->push(data); _asyncStructQueueMutex.unlock(); _sleepCondition.notify_one();}关于addImage</span>
a:Texture2D * TextureCache::addImage(const std::string &path)b:Texture2D* TextureCache::addImage(Image *image, const std::string &key)对a来说默认的key是文件名称对b来说可以自定义keya和b这两种方式都返回加载好的纹理,所以要进行用Texture2D类型的变量进行赋值。回收可以用void TextureCache::removeTexture(Texture2D* texture)或void TextureCache::removeTextureForKey(const std::string &textureKeyName)来进行获取可以用Texture2D* TextureCache::getTextureForKey(const std::string &textureKeyName) const
SpriteFrame的用法基本没变。
技术比较水,努力中
0 0
- cocos2d 3.x 纹理缓存
- 【Cocos2d-x 3.x】 精灵帧缓存和纹理缓存
- cocos2d-x 3.0纹理缓存
- Cocos2d-x -- 纹理缓存(Texture Cache)
- Cocos2d-x 纹理缓存(Texture Cache)
- Cocos2d-x3.x 精灵帧缓存和纹理缓存
- Cocos2d-X研究之v3.x纹理缓存详解
- [Cocos2d-x v3.x官方文档]纹理缓存
- [Cocos2d-x v3.x官方文档]纹理缓存
- cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
- 【cocos2d-x官方文档】纹理缓存(Texture Cache)
- cocos2d-x利用精灵表和纹理缓存实现优化
- cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
- cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
- cocos2d-x 优化(纹理渲染优化、资源缓存、内存优化)
- cocos2d-x 纹理研究
- Cocos2d-x 纹理管理
- Cocos2d-x 纹理优化
- error MSB4044: 未给任务“CppClean”的必需参数“FoldersToClean”赋值
- 手把手教你解决android网络请求问题:android.os.NetworkOnMainThreadException
- leetcode刷题记录5--依旧数组
- PowerDesigner 物理数据模型生成数据库脚本并执行
- Crashlytics was applied to a project without an Android plugin.
- cocos2d 3.x 纹理缓存
- web.xml配置
- netfiletr libipq用户定义chain描述
- linux修改hostname
- [Python监控]psutil模块简单使用
- JSOUP入门指南-Java开发的HTML解析器
- 定时刷新同一个链接传递不同的参数
- STL
- spring3.1.1的各个jar作用