Cocos Creator API

1.3.0

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

SpriteFrame

: cc

A cc.SpriteFrame has:

  • texture: A cc.Texture2D that will be used by the _ccsg.Sprite
  • rectangle: A rectangle of the texture

    You can modify the frame of a _ccsg.Sprite by doing:

Note: It's not recommended to use SpriteFrame constructor (new SpriteFrame) because its memory usage can't be tracked in native environment,
if you know what you are doing, you may need to manually retain it after creation then release it when you no longer need it.

:

// load a cc.SpriteFrame with image path (Recommend)
var self = this;
var url = "test assets/PurpleMonster";
cc.loader.loadRes(url, cc.SpriteFrame, function (err, spriteFrame) {
var node = new cc.Node("New Sprite");
var sprite = node.addComponent(cc.Sprite);
sprite.spriteFrame = spriteFrame;
node.parent = self.node
});

_textureFilenameSetter String private readOnly

Use this property to set raw texture url during loading

insetTop Number

Top border of the sprite

insetBottom Number

Bottom border of the sprite

insetLeft Number

Left border of the sprite

insetRight Number

Right border of the sprite

rawUrl String readOnly

Returns the url of this asset's first raw file, if none of rawFile exists, it will returns an empty string.

rawUrls String[] readOnly

Returns the url of this asset's raw files, if none of rawFile exists, it will returns an empty array.

_rawFiles String[] private

在 lite 版的 Fireball 里,raw asset 并不仅仅是在 properties 里声明了 rawType 才有, 而是每个 asset 都能指定自己的 raw file url。这些 url 就存在 _rawFiles 字段中。 AssetLibrary 并不会帮你加载这些 url,除非你声明了 rawType。

_uuid String private

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

SpriteFrame
(
  • [filename ]
  • [rect ]
  • [rotated ]
  • [offset ]
  • [originalSize ]
)

Constructor of SpriteFrame class.
Note: It's not recommended to use SpriteFrame constructor (new SpriteFrame) because its memory usage can't be tracked in native environment,
if you know what you are doing, you may need to manually retain it after creation then release it when you no longer need it.

filename optional String | Texture2D
rect optional Rect
rotated optional Boolean

Whether the frame is rotated in the texture

offset optional Vec2

The offset of the frame in the texture

originalSize optional Size

The size of the frame in the texture

textureLoaded ( ) boolean

Returns whether the texture have been loaded

:

addLoadedEventListener
(
  • callback
  • target
)
deprecated

: since 3.1, please use EventTarget API instead

Add a event listener for texture loaded event.

callback Function
target Object

isRotated ( ) Boolean

Returns whether the sprite frame is rotated in the texture.

:

setRotated
(
  • bRotated
)

Set whether the sprite frame is rotated in the texture.

bRotated Boolean

getRect ( ) Rect

Returns the rect of the sprite frame in the texture.

:

: Rect

setRect
(
  • rect
)

Sets the rect of the sprite frame in the texture.

rect Rect

getOriginalSize ( ) Size

Returns the original size of the trimmed image.

:

: Size

setOriginalSize
(
  • size
)

Sets the original size of the trimmed image.

size Size

getTexture ( ) Texture2D

Returns the texture of the frame.

:

_refreshTexture
(
  • texture
)

Sets the texture of the frame, the texture is retained automatically.

texture Texture2D

getOffset ( ) Vec2

Returns the offset of the frame in the texture.

:

: Vec2

setOffset
(
  • offsets
)

Sets the offset of the frame in the texture.

offsets Vec2

clone ( ) SpriteFrame

Clone the sprite frame.

ensureLoadTexture ( )

If a loading scene is marked as asyncLoadAssets, all the textures of the SpriteFrame which associated by user's custom Components in the scene, will not preload automatically. These textures will be load when Sprite component is going to render the SpriteFrames. You can call this method if you want to load the texture early.

:

if (spriteFrame.textureLoaded()) {
    this._onSpriteFrameLoaded();
}
else {
    spriteFrame.once('load', this._onSpriteFrameLoaded, this);
    spriteFrame.ensureLoadTexture();
}

serialize ( ) String private

应 AssetDB 要求提供这个方法

:

: String

createNode
(
  • callback
)

Create a new node using this asset in the scene.
If this type of asset dont have its corresponding node type, this method should be null.

callback Function
  • error String

    null or the error info

  • node Object

    the created node or null

_setRawFiles
(
  • rawFiles
)
private

Set raw file names for this asset.

rawFiles String[]

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