Class cc.Scale9Sprite

Class Summary
Constructor Attributes Constructor Name and Description
 
A 9-slice sprite for cocos2d.

Method Summary

Class Detail

cc.Scale9Sprite()
A 9-slice sprite for cocos2d. 9-slice scaling allows you to specify how scaling is applied to specific areas of a sprite. With 9-slice scaling (3x3 grid), you can ensure that the sprite does not become distorted when scaled.
See:
http://yannickloriot.com/library/ios/cccontrolextension/Classes/CCScale9Sprite.html

Field Detail

{cc.Rect} capInsets
- The cap insets of the 9-slice sprite
{Number} insetBottom
- The bottom inset of the 9-slice sprite
{Number} insetLeft
- The left inset of the 9-slice sprite
{Number} insetRight
- The right inset of the 9-slice sprite
{Number} insetTop
- The top inset of the 9-slice sprite
{cc.Size} preferredSize
- The preferred size of the 9-slice sprite

Method Detail

  • addLoadedEventListener(callback, target)
    add texture loaded event listener
    Parameters:
    {Function} callback
    {Object} target
    Deprecated:
    since 3.1, please use addEventListener instead
  • <static> {cc.Scale9Sprite} cc.Scale9Sprite.create(file, rect, capInsets)
    Creates a 9-slice sprite with a texture file, a delimitation zone and with the specified cap insets.
    Parameters:
    {String|cc.SpriteFrame} file
    file name of texture or a cc.Sprite object
    {cc.Rect} rect
    the rect of the texture
    {cc.Rect} capInsets
    the cap insets of cc.Scale9Sprite
    Returns:
    {cc.Scale9Sprite}
  • <static> {cc.Scale9Sprite} cc.Scale9Sprite.createWithSpriteFrame(spriteFrame, capInsets)
    Parameters:
    spriteFrame
    capInsets
    Returns:
    {cc.Scale9Sprite}
  • <static> {cc.Scale9Sprite} cc.Scale9Sprite.createWithSpriteFrameName(spriteFrameName, capInsets)
    Parameters:
    spriteFrameName
    capInsets
    Returns:
    {cc.Scale9Sprite}
  • {Scale9Sprite} ctor(file, rect, capInsets)
    Constructor function. override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
    Parameters:
    {string|cc.SpriteFrame} file
    file name of texture or a SpriteFrame
    {cc.Rect} rect
    {cc.Rect} capInsets
    Returns:
    {Scale9Sprite}
  • {number} getInsetBottom()
    Gets the bottom side inset
    Returns:
    {number}
  • {number} getInsetLeft()
    Gets the left side inset
    Returns:
    {number}
  • {number} getInsetRight()
    Gets the right side inset
    Returns:
    {number}
  • {number} getInsetTop()
    Gets the top side inset
    Returns:
    {number}
  • getOriginalSize()
    Original sprite's size.
  • {boolean} init()
    Initializes a cc.Scale9Sprite. please do not call this function by yourself, you should pass the parameters to constructor to initialize it.
    Returns:
    {boolean}
  • {boolean} initWithBatchNode(batchNode, rect, rotated, capInsets)
    Initializes a 9-slice sprite with a SpriteBatchNode.
    Parameters:
    {cc.SpriteBatchNode} batchNode
    {cc.Rect} rect
    {boolean|cc.Rect} rotated
    {cc.Rect} capInsets Optional
    Returns:
    {boolean}
  • initWithFile(file, rect, capInsets)
    Initializes a 9-slice sprite with a texture file, a delimitation zone and with the specified cap insets. Once the sprite is created, you can then call its "setContentSize:" method to resize the sprite will all it's 9-slice goodness intact. It respects the anchorPoint too.
    Parameters:
    {String} file
    The name of the texture file.
    {cc.Rect} rect
    The rectangle that describes the sub-part of the texture that is the whole image. If the shape is the whole texture, set this to the texture's full rect.
    {cc.Rect} capInsets
    The values to use for the cap insets.
  • initWithSpriteFrame(spriteFrame, capInsets)
    Initializes a 9-slice sprite with an sprite frame and with the specified cap insets. Once the sprite is created, you can then call its "setContentSize:" method to resize the sprite will all it's 9-slice goodness interact. It respects the anchorPoint too.
    Parameters:
    spriteFrame
    The sprite frame object.
    capInsets
    The values to use for the cap insets.
  • initWithSpriteFrameName(spriteFrameName, capInsets)
    Initializes a 9-slice sprite with an sprite frame name and with the specified cap insets. Once the sprite is created, you can then call its "setContentSize:" method to resize the sprite will all it's 9-slice goodness interact. It respects the anchorPoint too.
    Parameters:
    spriteFrameName
    The sprite frame name.
    capInsets
    The values to use for the cap insets.
  • {Boolean} isFlippedX()

    Returns the flag which indicates whether the widget is flipped horizontally or not.

    It only flips the texture of the widget, and not the texture of the widget's children.
    Also, flipping the texture doesn't alter the anchorPoint.
    If you want to flip the anchorPoint too, and/or to flip the children too use:
    widget->setScaleX(sprite->getScaleX() * -1);

    Since:
    v3.3
    Returns:
    {Boolean} true if the widget is flipped horizontally, false otherwise.
  • {Boolean} isFlippedY()

    Return the flag which indicates whether the widget is flipped vertically or not.

    It only flips the texture of the widget, and not the texture of the widget's children.
    Also, flipping the texture doesn't alter the anchorPoint.
    If you want to flip the anchorPoint too, and/or to flip the children too use:
    widget->setScaleY(widget->getScaleY() * -1);

    Since:
    v3.3
    Returns:
    {Boolean} true if the widget is flipped vertically, false otherwise.
  • isOpacityModifyRGB()
    returns whether or not the opacity will be applied using glColor(R,G,B,opacity) or glColor(opacity, opacity, opacity, opacity);
    Since:
    v0.8
  • resizableSpriteWithCapInsets(capInsets)
    Creates and returns a new sprite object with the specified cap insets. You use this method to add cap insets to a sprite or to change the existing cap insets of a sprite. In both cases, you get back a new image and the original sprite remains untouched.
    Parameters:
    {cc.Rect} capInsets
    The values to use for the cap insets.
  • setColor(color)
    Color: conforms to CCRGBAProtocol protocol
    Parameters:
    color
  • setContentSize(size, height)
    Sets the untransformed size of the Scale9Sprite.
    Parameters:
    {cc.Size|Number} size
    The untransformed size of the Scale9Sprite or The untransformed size's width of the Scale9Sprite.
    {Number} height Optional
    The untransformed size's height of the Scale9Sprite.
  • setFlippedX(flippedX)
    Sets whether the widget should be flipped horizontally or not.
    Parameters:
    flippedX
    true if the widget should be flipped horizontally, false otherwise.
    Since:
    v3.3
  • setFlippedY(flippedY)
    Sets whether the widget should be flipped vertically or not.
    Parameters:
    flippedY
    true if the widget should be flipped vertically, false otherwise.
    Since:
    v3.3
  • setInsetBottom(insetBottom)
    Sets the bottom side inset
    Parameters:
    {number} insetBottom
  • setInsetLeft(insetLeft)
    Sets the left side inset
    Parameters:
    {Number} insetLeft
  • setInsetRight(insetRight)
    Sets the right side inset
    Parameters:
    {Number} insetRight
  • setInsetTop(insetTop)
    Sets the top side inset
    Parameters:
    {Number} insetTop
  • setOpacity(opacity)
    Opacity: conforms to CCRGBAProtocol protocol
    Parameters:
    opacity
  • setOpacityModifyRGB(value)
    sets the premultipliedAlphaOpacity property. If set to NO then opacity will be applied as: glColor(R,G,B,opacity); If set to YES then opacity will be applied as: glColor(opacity, opacity, opacity, opacity ); Textures with premultiplied alpha will have this property by default on YES. Otherwise the default value is NO
    Parameters:
    value
    Since:
    v0.8
  • setSpriteFrame(spriteFrame)
    set the sprite frame of cc.Scale9Sprite
    Parameters:
    {cc.SpriteFrame} spriteFrame
  • setState(state)
    Sets cc.Scale9Sprite's state
    Parameters:
    {Number} state
    Since:
    v3.3
  • {boolean} textureLoaded()
    return texture is loaded
    Returns:
    {boolean}
  • {boolean} updateWithBatchNode(batchNode, originalRect, rotated, capInsets)
    Update the scale9Sprite with a SpriteBatchNode.
    Parameters:
    {cc.SpriteBatchNode} batchNode
    {cc.Rect} originalRect
    {boolean} rotated
    {cc.Rect} capInsets
    Returns:
    {boolean}