Cocos Creator API

0.7.1

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

SpriteFrame

Extends Asset
Module: 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:

examples:

----------------------------------------------------
// 1. Create a cc.SpriteFrame with image path
var frame1 = new cc.SpriteFrame("res/grossini_dance.png",cc.rect(0,0,90,128));
var frame2 = new cc.SpriteFrame("res/grossini_dance.png",cc.rect(0,0,90,128),false,0,cc.size(90,128));

// 2. Create a cc.SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. var texture = cc.textureCache.addImage("res/grossini_dance.png"); var frame1 = new cc.SpriteFrame(texture, cc.rect(0,0,90,128)); var frame2 = new cc.SpriteFrame(texture, cc.rect(0,0,90,128),false,0,cc.size(90,128));

Properties

_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

_uuid String private

Inherited from Asset:

url String readOnly

Inherited from Asset:

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

urls String[] readOnly

Inherited from Asset:

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

_rawFiles String[] private

Inherited from Asset:

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

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

Methods

textureLoaded ( ) boolean

Returns whether the texture have been loaded

returns:

type: boolean

addLoadedEventListener
(
  • callback
  • target
)
deprecated

deprecated: since 3.1, please use EventTarget API instead

Add a event listener for texture loaded event.

name type description
callback Function
target Object

getRectInPixels ( ) Rect

Gets the rect of the frame in the texture.

returns:

type: Rect

setRectInPixels
(
  • rectInPixels
)

Sets the rect of the frame in the texture.

name type description
rectInPixels Rect

isRotated ( ) Boolean

Returns whether the sprite frame is rotated in the texture.

returns:

type: Boolean

setRotated
(
  • bRotated
)

Set whether the sprite frame is rotated in the texture.

name type description
bRotated Boolean

getRect ( ) Rect

Returns the rect of the sprite frame in the texture.

returns:

type: Rect

setRect
(
  • rect
)

Sets the rect of the sprite frame in the texture.

name type description
rect Rect

getOffsetInPixels ( ) Vec2

Returns the offset of the sprite frame in the texture in pixel.

returns:

type: Vec2

setOffsetInPixels
(
  • offsetInPixels
)

Sets the offset of the sprite frame in the texture in pixel.

name type description
offsetInPixels Vec2

getOriginalSizeInPixels ( ) Size

Returns the original size of the trimmed image.

returns:

type: Size

setOriginalSizeInPixels
(
  • sizeInPixels
)

Sets the original size of the trimmed image.

name type description
sizeInPixels Size

getOriginalSize ( ) Size

Returns the original size of the trimmed image.

returns:

type: Size

setOriginalSize
(
  • size
)

Sets the original size of the trimmed image.

name type description
size Size

getTexture ( ) Texture2D

Returns the texture of the frame.

returns:

type: Texture2D

_refreshTexture
(
  • texture
)

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

name type description
texture Texture2D

getOffset ( ) Vec2

Returns the offset of the frame in the texture.

returns:

type: Vec2

setOffset
(
  • offsets
)

Sets the offset of the frame in the texture.

name type description
offsets Vec2

clone ( ) SpriteFrame

Clone the sprite frame.

returns:

type: SpriteFrame

initWithTexture
(
  • texture
  • rect
  • [rotated =false]
  • [offset =cc.v2(0,0)]
  • [originalSize =rect.size]
)
Boolean

Initializes SpriteFrame with Texture, rect, rotated, offset and originalSize in pixels.
Please pass parameters to the constructor to initialize the sprite, do not call this function yourself.

name type description
texture String | cc.Texture2D
rect Rect

if parameters' length equal 2, rect in points, else rect in pixels

rotated optional Boolean false
offset optional Vec2 cc.v2(0,0)
originalSize optional Size rect.size

returns:

type: Boolean

copyWithZone ( ) SpriteFrame

Copy the sprite frame

returns:

type: SpriteFrame

copy ( ) cc.SpriteFrame

Copy the sprite frame

returns:

type: cc.SpriteFrame

cc.SpriteFrame.create
(
  • filename
  • rect
  • rotated
  • offset
  • originalSize
)
cc.SpriteFrame

Create a cc.SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels.
The originalSize is the size in pixels of the frame before being trimmed.

since v3.0, please use new constructor SpriteFrame/SpriteFrame:method instead.

name type description
filename String | cc.Texture2D
rect cc.Rect

if parameters' length equal 2, rect in points, else rect in pixels

rotated Boolean
offset cc.Vec2
originalSize cc.Size

returns:

type: cc.SpriteFrame

cc.SpriteFrame.createWithTexture ( ) deprecated

deprecated since v3.0, please use new construction instead

serialize ( ) String private

Inherited from Asset:

应 AssetDB 要求提供这个方法

returns:

type: String

createNode
(
  • callback
)

Inherited from Asset:

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.

name type description
callback Function
  • error String
    null or the error info
  • node Object
    the created node or null

_setRawFiles
(
  • rawFiles
)
private

Inherited from Asset:

Set raw extname for this asset.

name type description
rawFiles String[]

createNodeByInfo
(
  • Info
  • callback
)

Inherited from RawAsset:

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

name type description
Info Object
callback Function
  • error String
    null or the error info
  • node Object
    the created node or null

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