textureCache
Class
cc.textureCache is a singleton object, it's the global cache for cc.Texture2D
Index
Methods
description
DescriptiontextureForKey
Returns an already created texture. Returns null if the texture doesn't exist.getTextureForKey
Returns an already created texture. Returns null if the texture doesn't exist.getTextureColors
getAllTextures
get all texturesremoveAllTextures
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 sameremoveTexture
Deletes a texture from the cache given a texture.removeTextureForKey
Deletes a texture from the cache given a its key name.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, .gifcacheImage
Cache 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
textureKeyName
String
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
textureKeyName
String
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
texture
HTMLImageElement
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
texture
HTMLImageElement
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
textureKeyName
String
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
path
Stringtexture
HTMLImageElement | HTMLCanvasElement