Cocos Creator API

0.7.1

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

spriteFrameCache

Module: cc

cc.spriteFrameCache is a singleton that handles the loading of the sprite frames. It saves in a cache the sprite frames.

Methods

addSpriteFrames
(
  • url
  • texture
)

Adds multiple Sprite Frames from a plist or json file.
A texture will be loaded automatically. The texture name will composed by replacing the .plist or .json suffix with .png
If you want to use another texture, you should use the addSpriteFrames:texture method.

name type description
url String

file path

texture HTMLImageElement | Texture2D | string

examples:

----------------------------------------------------
// add SpriteFrames to SpriteFrameCache With File
cc.spriteFrameCache.addSpriteFrames(s_grossiniPlist);
cc.spriteFrameCache.addSpriteFrames(s_grossiniJson);

addSpriteFrame
(
  • frame
  • frameName
)

Adds an sprite frame with a given name.
If the name already exists, then the contents of the old name will be replaced with the new one.

name type description
frame SpriteFrame
frameName String

removeSpriteFrames ( )

Purges the dictionary of loaded sprite frames.
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.

removeSpriteFrameByName
(
  • name
)

Deletes an sprite frame from the sprite frame cache.

name type description
name String

removeSpriteFramesFromFile
(
  • url
)

Removes multiple Sprite Frames from a plist file.
Sprite Frames stored in this file will be removed.
It is convinient to call this method when a specific texture needs to be removed.

name type description
url String

Plist filename

removeSpriteFramesFromTexture
(
  • texture
)

Removes all Sprite Frames associated with the specified textures.
It is convenient to call this method when a specific texture needs to be removed.

name type description
texture HTMLImageElement | HTMLCanvasElement | Texture2D

getSpriteFrame
(
  • name
)
SpriteFrame

Returns an Sprite Frame that was previously added.
If the name is not found it will return nil.
You should retain the returned copy if you are going to use it.

name type description
name String

name of SpriteFrame

returns:

type: SpriteFrame

examples:

----------------------------------------------------
//get a SpriteFrame by name
var frame = cc.spriteFrameCache.getSpriteFrame("grossini_dance_01.png");

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