Cocos Creator API

1.3.0

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

textureCache

: cc

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

description ( ) String

Description

:

: String

textureForKey
(
  • textureKeyName
)
Texture2D | Null deprecated

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

textureKeyName String

:

: Texture2D | Null

:

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

getTextureForKey
(
  • textureKeyName
)
Texture2D | Null

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

textureKeyName String

:

: Texture2D | Null

:

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

getTextureColors
(
  • texture
)
Array

texture Image

:

: Array

:

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

getAllTextures ( ) Texture2D[]

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

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

:

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

removeTexture
(
  • texture
)

Deletes a texture from the cache given a texture.

texture Image

:

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

removeTextureForKey
(
  • textureKeyName
)

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

textureKeyName String

:

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

url String
cb Function
target Object

:

:

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

cacheImage
(
  • path
  • texture
)

Cache the image data.

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.

image HTMLImageElement | HTMLCanvasElement
key String

:

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