Singleton that handles the loading of textures. More...
Inherits Ref.
Public Member Functions | |
TextureCache () | |
@js ctor | |
virtual | ~TextureCache () |
@js NA @lua NA | |
virtual std::string | getDescription () const |
@js NA @lua NA | |
Texture2D * | addImage (const std::string &filepath) |
Returns a Texture2D object given an filename. More... | |
virtual void | addImageAsync (const std::string &filepath, const std::function< void(Texture2D *)> &callback) |
Returns a Texture2D object given a file image. More... | |
virtual void | unbindImageAsync (const std::string &filename) |
Unbind a specified bound image asynchronous callback. More... | |
virtual void | unbindAllImageAsync () |
Unbind all bound image asynchronous load callbacks. More... | |
Texture2D * | addImage (Image *image, const std::string &key) |
Returns a Texture2D object given an Image. More... | |
Texture2D * | getTextureForKey (const std::string &key) const |
Returns an already created texture. More... | |
bool | reloadTexture (const std::string &fileName) |
Reload texture from the image file. More... | |
void | removeAllTextures () |
Purges the dictionary of loaded textures. More... | |
void | removeUnusedTextures () |
Removes unused textures. More... | |
void | removeTexture (Texture2D *texture) |
Deletes a texture from the cache given a texture. | |
void | removeTextureForKey (const std::string &key) |
Deletes a texture from the cache given a its key name. More... | |
std::string | getCachedTextureInfo () const |
Output to CCLOG the current contents of this TextureCache. More... | |
void | waitForQuit () |
Called by director, please do not called outside. | |
std::string | getTextureFilePath (Texture2D *texture) const |
Get the file path of the texture. More... | |
void | renameTextureWithKey (const std::string &srcName, const std::string &dstName) |
Reload texture from a new file. More... | |
Public Member Functions inherited from Ref | |
void | retain () |
Retains the ownership. More... | |
void | release () |
Releases the ownership immediately. More... | |
Ref * | autorelease () |
Releases the ownership sometime soon automatically. More... | |
unsigned int | getReferenceCount () const |
Returns the Ref's current reference count. More... | |
virtual | ~Ref () |
Destructor. More... | |
Additional Inherited Members | |
Public Attributes inherited from Ref | |
unsigned int | _ID |
object id, ScriptSupport need public _ID | |
int | _luaID |
Lua reference id. | |
void * | _scriptObject |
scriptObject, support for swift | |
bool | _rooted |
When true, it means that the object was already rooted. | |
Singleton that handles the loading of textures.
Once the texture is loaded, the next time it will return. A reference of the previously loaded texture reducing GPU & CPU memory.
Texture2D* addImage | ( | const std::string & | filepath | ) |
Returns a Texture2D object given an filename.
If the filename was not previously loaded, it will create a new Texture2D. Object and it will return it. It will use the filename as a key. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .jpeg, .pvr.
filepath | The file path. |
|
virtual |
Returns a Texture2D object given a file image.
If the file image was not previously loaded, it will create a new Texture2D object and it will return it. Otherwise it will load a texture in a new thread, and when the image is loaded, the callback will be called with the Texture2D as a parameter. The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback. Supported image extensions: .png, .jpg
filepath | The file path. |
callback | A callback function would be invoked after the image is loaded. |
|
virtual |
Unbind a specified bound image asynchronous callback.
In the case an object who was bound to an image asynchronous callback was destroyed before the callback is invoked, the object always need to unbind this callback manually.
filename | It's the related/absolute path of the file image. |
|
virtual |
Unbind all bound image asynchronous load callbacks.
Texture2D* addImage | ( | Image * | image, |
const std::string & | key | ||
) |
Returns a Texture2D object given an Image.
If the image was not previously loaded, it will create a new Texture2D object and it will return it. Otherwise it will return a reference of a previously loaded image.
key | The "key" parameter will be used as the "key" for the cache. If "key" is nil, then a new texture will be created each time. |
Texture2D* getTextureForKey | ( | const std::string & | key | ) | const |
Returns an already created texture.
Returns nil if the texture doesn't exist.
key | It's the related/absolute path of the file image. |
bool reloadTexture | ( | 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.
fileName | It's the related/absolute path of the file image. |
void removeAllTextures | ( | ) |
Purges the dictionary of loaded textures.
Call this method if you receive the "Memory Warning". In the short term: it will free some resources preventing your app from being killed. In the medium term: it will allocate more resources. In the long term: it will be the same.
void removeUnusedTextures | ( | ) |
Removes unused textures.
Textures that have a retain count of 1 will be deleted. It is convenient to call this method after when starting a new Scene.
void removeTextureForKey | ( | const std::string & | key | ) |
Deletes a texture from the cache given a its key name.
key | It's the related/absolute path of the file image. |
std::string getCachedTextureInfo | ( | ) | const |
Output to CCLOG the current contents of this TextureCache.
This will attempt to calculate the size of each texture, and the total texture memory in use.
std::string getTextureFilePath | ( | Texture2D * | texture | ) | const |
Get the file path of the texture.
texture | A Texture2D object pointer. |
void renameTextureWithKey | ( | const std::string & | srcName, |
const std::string & | dstName | ||
) |
Reload texture from a new file.
This function is mainly for editor, won't suggest use it in game for performance reason.
srcName | Original texture file name. |
dstName | New texture file name. |