textureCache Class
Module: cc
cc.textureCache is a singleton object, it's the global cache for cc.Texture2D
Index
Methods
descriptionDescriptiongetTextureForKeyReturns an already created texture.getTextureColorsgetAllTexturesget all texturesremoveAllTexturesPurges the dictionary of loaded textures.
removeTextureDeletes a texture from the cache given a texture.removeTextureForKeyDeletes a texture from the cache given a its key name.addImageobject and it will return it.cacheImageCache the image data.
Details
Methods
description
Description
| meta | description |
|---|---|
| Returns | String |
| Defined in | cocos2d/core/textures/CCTextureCache.js:44 |
getTextureForKey
Returns an already created texture. Returns null if the texture doesn't exist.
| meta | description |
|---|---|
| Returns | Texture2D | Null |
| Defined in | cocos2d/core/textures/CCTextureCache.js:53 |
Parameters
textureKeyNameString
Examples
------------------
var key = cc.textureCache.getTextureForKey("hello.png");
getTextureColors
| meta | description |
|---|---|
| Returns | Array |
| Defined in | cocos2d/core/textures/CCTextureCache.js:83 |
Parameters
textureHTMLImageElement
Examples
---------------
var cacheTextureForColor = cc.textureCache.getTextureColors(texture);
getAllTextures
get all textures
| meta | description |
|---|---|
| Returns | Texture2D[] |
| Defined in | cocos2d/core/textures/CCTextureCache.js:104 |
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
| meta | description |
|---|---|
| Defined in | cocos2d/core/textures/CCTextureCache.js:119 |
Examples
--------
cc.textureCache.removeAllTextures();
removeTexture
Deletes a texture from the cache given a texture.
| meta | description |
|---|---|
| Defined in | cocos2d/core/textures/CCTextureCache.js:137 |
Parameters
textureHTMLImageElement
Examples
-----
cc.textureCache.removeTexture(texture);
removeTextureForKey
Deletes a texture from the cache given a its key name.
| meta | description |
|---|---|
| Defined in | cocos2d/core/textures/CCTextureCache.js:156 |
Parameters
textureKeyNameString
Examples
------
cc.textureCache.removeTexture("hello.png");
addImage
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
| meta | description |
|---|---|
| Returns | Texture2D |
| Defined in | cocos2d/core/textures/CCTextureCache.js:178 |
Parameters
Examples
----
cc.textureCache.addImage("hello.png");
cacheImage
Cache the image data.
| meta | description |
|---|---|
| Defined in | cocos2d/core/textures/CCTextureCache.js:229 |
Parameters
pathStringtextureHTMLImageElement | HTMLCanvasElement