Cocos Creator API

1.0.0

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

textureCache

Module: cc

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

Methods

description ( ) String

Description

returns:

type: String

textureForKey
(
  • textureKeyName
)
Texture2D | Null deprecated

Returns an already created texture. Returns null if the texture doesn't exist.

name type description
textureKeyName String

returns:

type: Texture2D | Null

examples:

------------------
var key = cc.textureCache.textureForKey("hello.png");

getTextureForKey
(
  • textureKeyName
)
Texture2D | Null

Returns an already created texture. Returns null if the texture doesn't exist.

name type description
textureKeyName String

returns:

type: Texture2D | Null

examples:

------------------
var key = cc.textureCache.getTextureForKey("hello.png");

getKeyByTexture
(
  • texture
)
String | Null

name type description
texture Image

returns:

type: String | Null

examples:

---------
var key = cc.textureCache.getKeyByTexture(texture);

getTextureColors
(
  • texture
)
Array

name type description
texture Image

returns:

type: Array

examples:

---------------
var cacheTextureForColor = cc.textureCache.getTextureColors(texture);

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

examples:

--------
cc.textureCache.removeAllTextures();

removeTexture
(
  • texture
)

Deletes a texture from the cache given a texture.

name type description
texture Image

examples:

-----
cc.textureCache.removeTexture(texture);

removeTextureForKey
(
  • textureKeyName
)

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

name type description
textureKeyName String

examples:

------
cc.textureCache.removeTexture("hello.png");

addImage
(
  • url
  • cb
  • target
)
Texture2D

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

name type description
url String
cb Function
target Object

returns:

type: Texture2D

examples:

----
cc.textureCache.addImage("hello.png");

cacheImage
(
  • path
  • texture
)

Cache the image data.

name type description
path String
texture Image | HTMLImageElement | HTMLCanvasElement

addUIImage
(
  • image
  • key
)
Texture2D

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.

name type description
image HTMLImageElement | HTMLCanvasElement
key String

returns:

type: Texture2D

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index