Class cc.SpriteFrame
- Defined in: CCSpriteFrame.js
- Extends cc.Class
Constructor Attributes | Constructor Name and Description |
---|---|
cc.SpriteFrame(filename, rect, rotated, offset, originalSize)
A cc.SpriteFrame has: |
Method Summary
Class Detail
cc.SpriteFrame(filename, rect, rotated, offset, originalSize)
A cc.SpriteFrame has:
- texture: A cc.Texture2D that will be used by the cc.Sprite
- rectangle: A rectangle of the texture
You can modify the frame of a cc.Sprite by doing:
// 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));
- Parameters:
- {String|cc.Texture2D} filename
- {cc.Rect} rect
- If parameters' length equal 2, rect in points, else rect in pixels
- {Boolean} rotated Optional
- Whether the frame is rotated in the texture
- {cc.Point} offset Optional
- The offset of the frame in the texture
- {cc.Size} originalSize Optional
- The size of the frame in the texture
Method Detail
-
addLoadedEventListener(callback, target)Add a event listener for texture loaded event.
- Parameters:
- {Function} callback
- {Object} target
- Deprecated:
- since 3.1, please use addEventListener instead
-
{SpriteFrame} clone()Clone the sprite frame
- Returns:
- {SpriteFrame}
-
{cc.SpriteFrame} copy()Copy the sprite frame
- Returns:
- {cc.SpriteFrame}
-
{cc.SpriteFrame} copyWithZone()Copy the sprite frame
- Returns:
- {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.- Parameters:
- {String|cc.Texture2D} filename
- {cc.Rect} rect
- if parameters' length equal 2, rect in points, else rect in pixels
- {Boolean} rotated
- {cc.Point} offset
- {cc.Size} originalSize
- Deprecated:
- since v3.0, please use new construction instead
- Returns:
- {cc.SpriteFrame}
- See:
- cc.SpriteFrame
-
<static> cc.SpriteFrame.createWithTexture()
- Deprecated:
- since v3.0, please use new construction instead
- See:
- cc.SpriteFrame
-
{cc.Point} getOffset()Returns the offset of the frame in the texture
- Returns:
- {cc.Point}
-
{cc.Point} getOffsetInPixels()Returns the offset of the sprite frame in the texture in pixel
- Returns:
- {cc.Point}
-
{cc.Size} getOriginalSize()Returns the original size of the trimmed image
- Returns:
- {cc.Size}
-
{cc.Size} getOriginalSizeInPixels()Returns the original size of the trimmed image
- Returns:
- {cc.Size}
-
{cc.Rect} getRect()Returns the rect of the sprite frame in the texture
- Returns:
- {cc.Rect}
-
{cc.Rect} getRectInPixels()Gets the rect of the frame in the texture
- Returns:
- {cc.Rect}
-
{cc.Texture2D} getTexture()Returns the texture of the frame
- Returns:
- {cc.Texture2D}
-
{Boolean} initWithTexture(texture, rect, rotated, offset, originalSize)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.- Parameters:
- {String|cc.Texture2D} texture
- {cc.Rect} rect
- if parameters' length equal 2, rect in points, else rect in pixels
- {Boolean} rotated Optional, Default: false
- {cc.Point} offset Optional, Default: cc.p(0,0)
- {cc.Size} originalSize Optional, Default: rect.size
- Returns:
- {Boolean}
-
{Boolean} isRotated()Returns whether the sprite frame is rotated in the texture.
- Returns:
- {Boolean}
-
setOffset(offsets)Sets the offset of the frame in the texture
- Parameters:
- {cc.Point} offsets
-
setOffsetInPixels(offsetInPixels)Sets the offset of the sprite frame in the texture in pixel
- Parameters:
- {cc.Point} offsetInPixels
-
setOriginalSize(sizeInPixels)Sets the original size of the trimmed image
- Parameters:
- {cc.Size} sizeInPixels
-
setOriginalSizeInPixels(sizeInPixels)Sets the original size of the trimmed image
- Parameters:
- {cc.Size} sizeInPixels
-
setRect(rect)Sets the rect of the sprite frame in the texture
- Parameters:
- {cc.Rect} rect
-
setRectInPixels(rectInPixels)Sets the rect of the frame in the texture
- Parameters:
- {cc.Rect} rectInPixels
-
setRotated(bRotated)Set whether the sprite frame is rotated in the texture.
- Parameters:
- {Boolean} bRotated
-
setTexture(texture)Sets the texture of the frame, the texture is retained automatically
- Parameters:
- {cc.Texture2D} texture
-
{boolean} textureLoaded()Returns whether the texture have been loaded
- Returns:
- {boolean}