Class cc.SpriteFrame

Class Summary
Constructor Attributes Constructor Name and Description
 

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:

Method Summary

Class Detail

cc.SpriteFrame()

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:

var texture = cc.TextureCache.getInstance().addImage(s_dragon_animation);
var frame0 = cc.SpriteFrame.createWithTexture(texture, cc.rect(132 * 0, 132 * 0, 132, 132));

Method Detail

  • {cc.SpriteFrame} copyWithZone()
    copy a new SpriteFrame
    Returns:
    {cc.SpriteFrame}
  • <static> {cc.SpriteFrame} cc.SpriteFrame.create(filename, rect, rotated, offset, originalSize)

    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} filename
    {cc.Rect} rect
    if parameters' length equal 2, rect in points, else rect in pixels
    {Boolean} rotated
    {cc.Point} offset
    {cc.Size} originalSize
    Returns:
    {cc.SpriteFrame}
  • <static> {cc.SpriteFrame} cc.SpriteFrame.createWithTexture(texture, rect, rotated, offset, originalSize)
    Create a cc.SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
    //Create a cc.SpriteFrame with a texture, rect in texture.
    var frame1 = cc.SpriteFrame.createWithTexture("grossini_dance.png",cc.rect(0,0,90,128));
    
    //Create a cc.SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.
    var frame2 = cc.SpriteFrame.createWithTexture(texture, frameRect, rotated, offset, sourceSize);
    Parameters:
    {cc.Texture2D} texture
    {cc.Rect} rect
    if parameters' length equal 2, rect in points, else rect in pixels
    {Boolean} rotated Optional
    {cc.Point} offset Optional
    {cc.Size} originalSize Optional
    Returns:
    {cc.SpriteFrame}
  • {cc.Point} getOffset()
    Offset getter
    Returns:
    {cc.Point}
  • {cc.Point} getOffsetInPixels()
    get offset of the frame
    Returns:
    {cc.Point}
  • {cc.Size} getOriginalSize()
    get original size of the trimmed image
    Returns:
    {cc.Size}
  • {cc.Size} getOriginalSizeInPixels()
    get original size of the trimmed image
    Returns:
    {cc.Size}
  • {cc.Rect} getRect()
    get rect of the frame
    Returns:
    {cc.Rect}
  • {cc.Rect} getRectInPixels()
    Returns:
    {cc.Rect}
  • {cc.Texture2D} getTexture()
    get 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.
    Parameters:
    {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}
  • initWithTextureFilename(filename, rect, rotated, offset, originalSize)

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

    Parameters:
    {string} filename
    {cc.Rect} rect
    if parameters' length equal 2, rect in points, else rect in pixels
    {Boolean} rotated
    {cc.Point} offset Optional, Default: cc.p(0,0)
    {cc.Size} originalSize Optional, Default: rect.size
  • {Boolean} isRotated()

    return is rotated of SpriteFrame.

    Returns:
    {Boolean}
  • setOffset(offsets)
    offset setter
    Parameters:
    {cc.Point} offsets
  • setOffsetInPixels(offsetInPixels)
    set offset of the frame
    Parameters:
    {cc.Point} offsetInPixels
  • setOriginalSize(sizeInPixels)
    set original size of the trimmed image
    Parameters:
    {cc.Size} sizeInPixels
  • setOriginalSizeInPixels(sizeInPixels)
    set original size of the trimmed image
    Parameters:
    {cc.Size} sizeInPixels
  • setRect(rect)
    set rect of the frame
    Parameters:
    {cc.Rect} rect
  • setRectInPixels(rectInPixels)
    Parameters:
    {cc.Rect} rectInPixels
  • setRotated(bRotated)
    set SpriteFrame is rotated
    Parameters:
    {Boolean} bRotated
  • setTexture(texture)
    set texture of the frame, the texture is retained
    Parameters:
    {cc.Texture2D} texture