Add function to texture cache for studio to check if texture have been already loaded

This commit is contained in:
XiaoFeng 2015-04-23 16:50:28 +08:00
parent 944184b5d0
commit faddbd8e71
4 changed files with 43 additions and 0 deletions

View File

@ -292,6 +292,18 @@ void SpriteFrameCache::addSpriteFramesWithFile(const std::string& plist)
}
}
bool SpriteFrameCache::isSpriteFramesWithFileLoaded(const std::string& plist)
{
bool result = false;
if (_loadedFileNames->find(plist) != _loadedFileNames->end())
{
result = true;
}
return result;
}
void SpriteFrameCache::addSpriteFrame(SpriteFrame* frame, const std::string& frameName)
{
_spriteFrames.insert(frameName, frame);

View File

@ -140,6 +140,15 @@ public:
*/
void addSpriteFrame(SpriteFrame *frame, const std::string& frameName);
/** Check if multiple Sprite Frames from a plist file have been loaded.
* @js NA
* @lua NA
*
* @param plist Plist file name.
* @return True if the file is loaded.
*/
bool isSpriteFramesWithFileLoaded(const std::string& plist);
/** Purges the dictionary of loaded sprite frames.
* Call this method if you receive the "Memory Warning".
* In the short term: it will free some resources preventing your app from being killed.

View File

@ -403,6 +403,21 @@ Texture2D* TextureCache::addImage(Image *image, const std::string &key)
return texture;
}
bool TextureCache::isTextureLoaded(const std::string& fileName)
{
bool result = false;
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName);
if (fullpath.size() > 0)
{
if (_textures.find(fullpath) != _textures.end()) {
result = true;
}
}
return result;
}
bool TextureCache::reloadTexture(const std::string& fileName)
{
Texture2D * texture = nullptr;

View File

@ -151,6 +151,13 @@ public:
Texture2D* getTextureForKey(const std::string& key) const;
CC_DEPRECATED_ATTRIBUTE Texture2D* textureForKey(const std::string& key) const { return getTextureForKey(key); }
/** Check if texture file have already been loaded to cache.
* If the file have been loaded before, return true; otherwise return false.
* @param fileName It's the related/absolute path of the file image.
* @return True if the texture file is loaded.
*/
bool isTextureLoaded(const std::string& fileName);
/** Reload texture from the image file.
* If the file image hasn't loaded before, load it.
* Otherwise the texture will be reloaded from the file image.