Class cc.textureCache

Class Summary
Constructor Attributes Constructor Name and Description
 
cc.textureCache is a singleton object, it's the global cache for cc.Texture2D

Method Summary

Class Detail

cc.textureCache()
cc.textureCache is a singleton object, it's the global cache for cc.Texture2D

Method Detail

  • {cc.Texture2D} addETCImage(filename)

    Returns a Texture2D object given an ETC filename
    If the file image was not previously loaded, it will create a new CCTexture2D
    object and it will return it. Otherwise it will return a reference of a previously loaded image
    note:addETCImage does not support on HTML5

    Parameters:
    {String} filename
    Returns:
    {cc.Texture2D}
  • {cc.Texture2D} addPVRImage(path)

    Returns a Texture2D object given an PVR filename
    If the file 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

    Parameters:
    {String} path
    Returns:
    {cc.Texture2D}
  • {cc.Texture2D} addPVRTCImage(filename)

    Returns a Texture2D object given an PVR filename
    If the file image was not previously loaded, it will create a new CCTexture2D
    object and it will return it. Otherwise it will return a reference of a previously loaded image
    note: AddPVRTCImage does not support on HTML5

    Parameters:
    {String} filename
    Returns:
    {cc.Texture2D}
  • {cc.Texture2D} addUIImage(image, key)

    Returns a Texture2D object given an UIImage 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 "key" parameter will be used as the "key" for the cache.
    If "key" is null, then a new texture will be created each time.

    Parameters:
    {HTMLImageElement|HTMLCanvasElement} image
    {String} key
    Returns:
    {cc.Texture2D}
  • cacheImage(path, texture)
    Cache the image data
    Parameters:
    {String} path
    {Image|HTMLImageElement|HTMLCanvasElement} texture
  • {String} description()
    Description
    Returns:
    {String}
  • dumpCachedTextureInfo()

    Output to cc.log the current contents of this TextureCache
    This will attempt to calculate the size of each texture, and the total texture memory in use.

  • {String|Null} getKeyByTexture(texture)
    //example
    var key = cc.textureCache.getKeyByTexture(texture);
    Parameters:
    {Image} texture
    Returns:
    {String|Null}
  • {Array} getTextureColors(texture)
    //example
    var cacheTextureForColor = cc.textureCache.getTextureColors(texture);
    Parameters:
    {Image} texture
    Returns:
    {Array}
  • {cc.Texture2D|Null} getTextureForKey(textureKeyName)
    Returns an already created texture. Returns null if the texture doesn't exist.
    //example
    var key = cc.textureCache.getTextureForKey("hello.png");
    Parameters:
    {String} textureKeyName
    Returns:
    {cc.Texture2D|Null}
  • 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

    //example
    cc.textureCache.removeAllTextures();
  • removeTexture(texture)
    Deletes a texture from the cache given a texture
    //example
    cc.textureCache.removeTexture(texture);
    Parameters:
    {Image} texture
  • removeTextureForKey(textureKeyName)
    Deletes a texture from the cache given a its key name
    //example
    cc.textureCache.removeTexture("hello.png");
    Parameters:
    {String} textureKeyName
  • {cc.Texture2D|Null} textureForKey(textureKeyName)
    Returns an already created texture. Returns null if the texture doesn't exist.
    //example
    var key = cc.textureCache.textureForKey("hello.png");
    Parameters:
    {String} textureKeyName
    Returns:
    {cc.Texture2D|Null}