textureCache Class
cc.textureCache is a singleton object, it's the global cache for cc.Texture2D
Index
Methods
descriptionDescriptiontextureForKeyReturns an already created texture. Returns null if the texture doesn't exist.getTextureForKeyReturns an already created texture. Returns null if the texture doesn't exist.getTextureColorsgetAllTexturesget all texturesremoveAllTexturesPurges 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 sameremoveTextureDeletes a texture from the cache given a texture.removeTextureForKeyDeletes a texture from the cache given a its key name.addImageReturns 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, .gifcacheImageCache the image data.
Details
Methods
description
Description
| meta | description |
|---|---|
| Returns | String |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:44 |
textureForKey
Returns an already created texture. Returns null if the texture doesn't exist.
| meta | description |
|---|---|
| Returns | Texture2D | Null |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:53 |
Parameters
textureKeyNameString
Examples
------------------
var key = cc.textureCache.textureForKey("hello.png");
getTextureForKey
Returns an already created texture. Returns null if the texture doesn't exist.
| meta | description |
|---|---|
| Returns | Texture2D | Null |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:66 |
Parameters
textureKeyNameString
Examples
------------------
var key = cc.textureCache.getTextureForKey("hello.png");
getTextureColors
| meta | description |
|---|---|
| Returns | Array |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:96 |
Parameters
textureHTMLImageElement
Examples
---------------
var cacheTextureForColor = cc.textureCache.getTextureColors(texture);
getAllTextures
get all textures
| meta | description |
|---|---|
| Returns | Texture2D[] |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:117 |
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 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:132 |
Examples
--------
cc.textureCache.removeAllTextures();
removeTexture
Deletes a texture from the cache given a texture.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:150 |
Parameters
textureHTMLImageElement
Examples
-----
cc.textureCache.removeTexture(texture);
removeTextureForKey
Deletes a texture from the cache given a its key name.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:169 |
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 | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:185 |
Parameters
Examples
----
cc.textureCache.addImage("hello.png");
cacheImage
Cache the image data.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/textures/CCTextureCache.js:201 |
Parameters
pathStringtextureHTMLImageElement | HTMLCanvasElement