Cocos Creator API

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

getKeyByTexture
(
  • texture
)
String | Null

名称 类型 描述
texture Image

返回:

类型: String | Null

示例:

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

getTextureColors
(
  • texture
)
Array

名称 类型 描述
texture Image

返回:

类型: Array

示例:

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

示例:

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

返回:

类型: Texture2D

示例:

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

返回:

类型: 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