Cocos Creator API

1.4.x

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");

getTextureColors
(
  • texture
)
Array

name type description
texture Image

returns:

type: Array

examples:

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

getAllTextures ( ) Texture2D[]

#en get all textures #zh 获取所有贴图

returns:

type: Texture2D[]

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