Cocos2d-x  v3.10
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Groups
TextureCache Class Reference

Singleton that handles the loading of textures. More...

Inherits Ref.

Public Member Functions

Texture2DaddImage (const std::string &filepath)
 Returns a Texture2D object with given an filename. More...
 
local addImage ( local filepath)
 Returns a Texture2D object with given an filename. More...
 
virtual void addImageAsync (const std::string &filepath, const std::function< void(Texture2D *)> &callback)
 Returns a Texture2D object with given a file image by asynchronous. More...
 
var addImageAsync ( var filepath, var callback)
 Returns a Texture2D object with given a file image by asynchronous. More...
 
local addImageAsync ( local filepath, local callback)
 Returns a Texture2D object with given a file image by asynchronous. More...
 
virtual void unbindImageAsync (const std::string &filename)
 Unbind a specified bound image asynchronous callback. More...
 
var unbindImageAsync ( var filename)
 Unbind a specified bound image asynchronous callback. More...
 
local unbindImageAsync ( local filename)
 Unbind a specified bound image asynchronous callback. More...
 
virtual void unbindAllImageAsync ()
 Unbind all bound image asynchronous load callbacks.
 
Texture2DaddImage (Image *image, const std::string &key)
 Returns a Texture2D object given an Image. More...
 
local addImage ( local image, local key)
 Returns a Texture2D object given an Image. More...
 
Texture2DgetTextureForKey (const std::string &key) const
 Returns an already created texture. More...
 
local getTextureForKey ( local key)
 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. More...
 
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 ()
 Wait for texture cache to quit befor destroy instance. More...
 
const 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...
 
local renameTextureWithKey ( local srcName, local dstName)
 Reload texture from a new file. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
local retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
local getReferenceCount ()
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor.
 

Static Public Member Functions

static TextureCachegetInstance ()
 Returns the shared instance of the cache.
 
local getInstance ()
 Returns the shared instance of the cache.
 
static TextureCachesharedTextureCache ()
static void destroyInstance ()
 Purges the cache. More...
 
static void purgeSharedTextureCache ()
static void reloadAllTextures ()
 Reload all textures. More...
 

Additional Inherited Members

- Public Attributes inherited from Ref
unsigned int _ID
 object id, ScriptSupport need public _ID
 
local _ID
 object id, ScriptSupport need public _ID
 
int _luaID
 Lua reference id.
 
local _luaID
 Lua reference id.
 
void * _scriptObject
 scriptObject, support for swift
 
local _scriptObject
 scriptObject, support for swift
 
bool _rooted
 When true, it means that the object was already rooted.
 
local _rooted
 When true, it means that the object was already rooted.
 
bool _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 
local _scriptOwned
 The life of the object is scrolled by the scripting engine. More...
 

Detailed Description

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.

Member Function Documentation

static TextureCache*
sharedTextureCache
( )
static
var sharedTextureCache ( )
static
local sharedTextureCache ( )
static
static void destroyInstance ( )
static

Purges the cache.

It releases the retained instance.

var destroyInstance ( )
static

Purges the cache.

It releases the retained instance.

local destroyInstance ( )
static

Purges the cache.

It releases the retained instance.

static void purgeSharedTextureCache ( )
static
var purgeSharedTextureCache ( )
static
local purgeSharedTextureCache ( )
static
static void reloadAllTextures ( )
static

Reload all textures.

Should not call it, called by frame work. Now the function do nothing, use VolatileTextureMgr::reloadAllTextures.

var reloadAllTextures ( )
static

Reload all textures.

Should not call it, called by frame work. Now the function do nothing, use VolatileTextureMgr::reloadAllTextures.

local reloadAllTextures ( )
static

Reload all textures.

Should not call it, called by frame work. Now the function do nothing, use VolatileTextureMgr::reloadAllTextures.

Texture2D* addImage ( const std::string &  filepath)

Returns a Texture2D object with 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 to cache the Texture2D object. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr. The path of the image file.

var addImage ( var  filepath)

Returns a Texture2D object with 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 to cache the Texture2D object. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr. The path of the image file.

local addImage ( local  filepath)

Returns a Texture2D object with 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 to cache the Texture2D object. Otherwise it will return a reference of a previously loaded image. Supported image extensions: .png, .bmp, .tiff, .jpeg, .pvr. The path of the image file.

virtual void addImageAsync ( const std::string &  filepath,
const std::function< void(Texture2D *)> &  callback 
)
virtual

Returns a Texture2D object with given a file image by asynchronous.

If the file image was not previously loaded, it will create a new Texture2D object. 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 The path of the image file. A callback function would be invoked after the image is loaded.

var addImageAsync ( var  filepath,
var  callback 
)
virtual

Returns a Texture2D object with given a file image by asynchronous.

If the file image was not previously loaded, it will create a new Texture2D object. 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 The path of the image file. A callback function would be invoked after the image is loaded.

local addImageAsync ( local  filepath,
local  callback 
)
virtual

Returns a Texture2D object with given a file image by asynchronous.

If the file image was not previously loaded, it will create a new Texture2D object. 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 The path of the image file. A callback function would be invoked after the image is loaded.

virtual void unbindImageAsync ( const std::string &  filename)
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. It's the related/absolute path of the file image.

var unbindImageAsync ( var  filename)
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. It's the related/absolute path of the file image.

local unbindImageAsync ( local  filename)
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. It's the related/absolute path of the file image.

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. The image to be added. 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. A texture object using specified Image.

var addImage ( var  image,
var  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. The image to be added. 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. A texture object using specified Image.

local addImage ( local  image,
local  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. The image to be added. 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. A texture object using specified Image.

Texture2D* getTextureForKey ( const std::string &  key) const

Returns an already created texture.

Returns nil if the texture doesn't exist. It's the related/absolute path of the file image. A texture object found by the key.

var getTextureForKey ( var  key)

Returns an already created texture.

Returns nil if the texture doesn't exist. It's the related/absolute path of the file image. A texture object found by the key.

local getTextureForKey ( local  key)

Returns an already created texture.

Returns nil if the texture doesn't exist. It's the related/absolute path of the file image. A texture object found by the key.

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. It's the related/absolute path of the file image. True if the reloading is succeed, otherwise return false.

var reloadTexture ( var  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. It's the related/absolute path of the file image. True if the reloading is succeed, otherwise return false.

local reloadTexture ( local  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. It's the related/absolute path of the file image. True if the reloading is succeed, otherwise return false.

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.

var 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.

local 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.

var 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.

local 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 removeTexture ( Texture2D texture)

Deletes a texture from the cache given a texture.

The texture object will be removed.

var removeTexture ( var  texture)

Deletes a texture from the cache given a texture.

The texture object will be removed.

local removeTexture ( local  texture)

Deletes a texture from the cache given a texture.

The texture object will be removed.

void removeTextureForKey ( const std::string &  key)

Deletes a texture from the cache given a its key name.

It's the related/absolute path of the file image.

var removeTextureForKey ( var  key)

Deletes a texture from the cache given a its key name.

It's the related/absolute path of the file image.

local removeTextureForKey ( local  key)

Deletes a texture from the cache given a its key name.

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.

var getCachedTextureInfo ( )

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.

local getCachedTextureInfo ( )

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.

void waitForQuit ( )

Wait for texture cache to quit befor destroy instance.

Called by director, please do not called outside.

var waitForQuit ( )

Wait for texture cache to quit befor destroy instance.

Called by director, please do not called outside.

local waitForQuit ( )

Wait for texture cache to quit befor destroy instance.

Called by director, please do not called outside.

const std::string
getTextureFilePath
( Texture2D texture) const

Get the file path of the texture.

A Texture2D object pointer.

The full path of the file.

var getTextureFilePath ( var  texture)

Get the file path of the texture.

A Texture2D object pointer.

The full path of the file.

local getTextureFilePath ( local  texture)

Get the file path of the texture.

A Texture2D object pointer.

The full path of the file.

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. Original texture file name. New texture file name.

var renameTextureWithKey ( var  srcName,
var  dstName 
)

Reload texture from a new file.

This function is mainly for editor, won't suggest use it in game for performance reason. Original texture file name. New texture file name.

local renameTextureWithKey ( local  srcName,
local  dstName 
)

Reload texture from a new file.

This function is mainly for editor, won't suggest use it in game for performance reason. Original texture file name. New texture file name.


The documentation for this class was generated from the following file: