Class cc.TextureCache

Class Summary
Constructor Attributes Constructor Name and Description
 
Implementation TextureCache

Method Summary

Class Detail

cc.TextureCache()
Implementation TextureCache

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} addImage(path)

    Returns a Texture2D object given an file image
    If the file image 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, .jpg, .gif

    //example
    cc.TextureCache.getInstance().addImage("hello.png");
    Parameters:
    {String} path
    Returns:
    {cc.Texture2D}
  • {cc.Texture2D} addImageAsync(path, target, selector)
    Loading the images asynchronously
    //example
    cc.TextureCache.getInstance().addImageAsync("hello.png", this, this.loadingCallBack);
    Parameters:
    {String} path
    {cc.Node} target
    {Function} selector
    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
  • ctor()
    Constructor
  • {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.

  • <static> {cc.TextureCache} cc.TextureCache.getInstance()
    Return ths shared instance of the cache
    Returns:
    {cc.TextureCache}
  • {String|Null} getKeyByTexture(texture)
    //example
    var key = cc.TextureCache.getInstance().getKeyByTexture(texture);
    Parameters:
    {Image} texture
    Returns:
    {String|Null}
  • {Array} getTextureColors(texture)
    //example
    var cacheTextureForColor = cc.TextureCache.getInstance().getTextureColors(texture);
    Parameters:
    {Image} texture
    Returns:
    {Array}
  • <static> cc.TextureCache.purgeSharedTextureCache()
    Purges the cache. It releases the retained instance.
  • 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.getInstance().removeAllTextures();
  • removeTexture(texture)
    Deletes a texture from the cache given a texture
    //example
    cc.TextureCache.getInstance().removeTexture(texture);
    Parameters:
    {Image} texture
  • removeTextureForKey(textureKeyName)
    Deletes a texture from the cache given a its key name
    //example
    cc.TextureCache.getInstance().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.getInstance().textureForKey("hello.png");
    Parameters:
    {String} textureKeyName
    Returns:
    {cc.Texture2D|Null}