Inherits from CCNode
Conforms to CCRGBAProtocol
Declared in CCScale9Sprite.h

Overview

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.

Tasks

Setting the Default Sizes

3x3 Grid Attributes

  •   capInsets

    The end-cap insets. On a non-resizeable sprite, this property is set to CGRectZero; the sprite does not use end caps and the entire sprite is subject to stretching.

    property
  •   insetLeft

    Sets the left side inset

    property
  •   insetTop

    Sets the top side inset

    property
  •   insetRight

    Sets the right side inset

    property
  •   insetBottom

    Sets the bottom side inset

    property

RGBA Protocol Properties

Create 9-Scale Sprites

  • – initWithFile: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 intract. It respects the anchorPoint too.

  • + spriteWithFile:rect:capInsets:

    Creates a 9-slice sprite with a texture file, a delimitation zone and with the specified cap insets.

  • – initWithFile:rect:

    Initializes a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • + spriteWithFile:rect:

    Creates a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks.

  • – initWithFile:capInsets:

    Initializes a 9-slice sprite with a texture file 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 intract. It respects the anchorPoint too.

  • + spriteWithFile:capInsets:

    Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

  • – initWithFile:

    Initializes a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • + spriteWithFile:

    Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

  • – initWithSpriteFrame: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 intract. It respects the anchorPoint too.

  • + spriteWithSpriteFrame:capInsets:

    Creates a 9-slice sprite with an sprite frame and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • – initWithSpriteFrame:

    Initializes a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • + spriteWithSpriteFrame:

    Creates a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • – initWithSpriteFrameName: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 intract. It respects the anchorPoint too.

  • + spriteWithSpriteFrameName:capInsets:

    Creates a 9-slice sprite with an sprite frame name and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • – initWithSpriteFrameName:

    Initializes a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

  • + spriteWithSpriteFrameName:

    Creates a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Modifying the 3x3 Grid

  • – resizableSpriteWithCapInsets:

    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.

Changing the Appearance

Properties

capInsets

The end-cap insets. On a non-resizeable sprite, this property is set to CGRectZero; the sprite does not use end caps and the entire sprite is subject to stretching.

@property (nonatomic, assign) CGRect capInsets

Discussion

The end-cap insets. On a non-resizeable sprite, this property is set to CGRectZero; the sprite does not use end caps and the entire sprite is subject to stretching.

Declared In

CCScale9Sprite.h

cascadeColorEnabled

Conforms to CCRGBAProtocol (v2.1) protocol.

@property (nonatomic, getter=isCascadeColorEnabled) BOOL cascadeColorEnabled

Discussion

Conforms to CCRGBAProtocol (v2.1) protocol.

Declared In

CCScale9Sprite.h

cascadeOpacityEnabled

Conforms to CCRGBAProtocol (v2.1) protocol.

@property (nonatomic, getter=isCascadeOpacityEnabled) BOOL cascadeOpacityEnabled

Discussion

Conforms to CCRGBAProtocol (v2.1) protocol.

Declared In

CCScale9Sprite.h

color

Conforms to CCRGBAProtocol protocol.

@property (nonatomic, readwrite) ccColor3B color

Discussion

Conforms to CCRGBAProtocol protocol.

Declared In

CCScale9Sprite.h

displayedColor

Conforms to CCRGBAProtocol (v2.1) protocol.

@property (nonatomic, readonly) ccColor3B displayedColor

Discussion

Conforms to CCRGBAProtocol (v2.1) protocol.

Declared In

CCScale9Sprite.h

displayedOpacity

Conforms to CCRGBAProtocol (v2.1) protocol.

@property (nonatomic, readonly) GLubyte displayedOpacity

Discussion

Conforms to CCRGBAProtocol (v2.1) protocol.

Declared In

CCScale9Sprite.h

insetBottom

Sets the bottom side inset

@property (nonatomic, assign) float insetBottom

Discussion

Sets the bottom side inset

Declared In

CCScale9Sprite.h

insetLeft

Sets the left side inset

@property (nonatomic, assign) float insetLeft

Discussion

Sets the left side inset

Declared In

CCScale9Sprite.h

insetRight

Sets the right side inset

@property (nonatomic, assign) float insetRight

Discussion

Sets the right side inset

Declared In

CCScale9Sprite.h

insetTop

Sets the top side inset

@property (nonatomic, assign) float insetTop

Discussion

Sets the top side inset

Declared In

CCScale9Sprite.h

opacity

Conforms to CCRGBAProtocol protocol.

@property (nonatomic, readwrite) GLubyte opacity

Discussion

Conforms to CCRGBAProtocol protocol.

Declared In

CCScale9Sprite.h

opacityModifyRGB

Conforms to CCRGBAProtocol protocol.

@property (nonatomic, getter=doesOpacityModifyRGB) BOOL opacityModifyRGB

Discussion

Conforms to CCRGBAProtocol protocol.

Declared In

CCScale9Sprite.h

originalSize

Original sprite’s size.

@property (nonatomic, readonly) CGSize originalSize

Discussion

Original sprite’s size.

Declared In

CCScale9Sprite.h

preferredSize

Preferred sprite’s size. By default the preferred size is the original size.

@property (nonatomic, assign) CGSize preferredSize

Discussion

Preferred sprite’s size. By default the preferred size is the original size.

Declared In

CCScale9Sprite.h

Class Methods

spriteWithFile:

Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

+ (id)spriteWithFile:(NSString *)file

Discussion

Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

Declared In

CCScale9Sprite.h

spriteWithFile:capInsets:

Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

+ (id)spriteWithFile:(NSString *)file capInsets:(CGRect)capInsets

Discussion

Creates a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks.

Declared In

CCScale9Sprite.h

spriteWithFile:rect:

Creates a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks.

+ (id)spriteWithFile:(NSString *)file rect:(CGRect)rect

Discussion

Creates a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks.

Declared In

CCScale9Sprite.h

spriteWithFile:rect:capInsets:

Creates a 9-slice sprite with a texture file, a delimitation zone and with the specified cap insets.

+ (id)spriteWithFile:(NSString *)file rect:(CGRect)rect capInsets:(CGRect)capInsets

Discussion

Creates a 9-slice sprite with a texture file, a delimitation zone and with the specified cap insets.

Declared In

CCScale9Sprite.h

spriteWithSpriteFrame:

Creates a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

+ (id)spriteWithSpriteFrame:(CCSpriteFrame *)spriteFrame

Discussion

Creates a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

spriteWithSpriteFrame:capInsets:

Creates a 9-slice sprite with an sprite frame and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

+ (id)spriteWithSpriteFrame:(CCSpriteFrame *)spriteFrame capInsets:(CGRect)capInsets

Discussion

Creates a 9-slice sprite with an sprite frame and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

spriteWithSpriteFrameName:

Creates a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

+ (id)spriteWithSpriteFrameName:(NSString *)spriteFrameName

Discussion

Creates a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

spriteWithSpriteFrameName:capInsets:

Creates a 9-slice sprite with an sprite frame name and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

+ (id)spriteWithSpriteFrameName:(NSString *)spriteFrameName capInsets:(CGRect)capInsets

Discussion

Creates a 9-slice sprite with an sprite frame name and the centre of its zone. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

Instance Methods

initWithFile:

Initializes a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

- (id)initWithFile:(NSString *)file

Parameters

file

The name of the texture file.

Discussion

Initializes a 9-slice sprite with a texture file. The whole texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithFile:capInsets:

Initializes a 9-slice sprite with a texture file 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 intract. It respects the anchorPoint too.

- (id)initWithFile:(NSString *)file capInsets:(CGRect)capInsets

Parameters

file

The name of the texture file.

capInsets

The values to use for the cap insets.

Discussion

Initializes a 9-slice sprite with a texture file 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 intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithFile:rect:

Initializes a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

- (id)initWithFile:(NSString *)file rect:(CGRect)rect

Parameters

file

The name of the texture file.

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.

Discussion

Initializes a 9-slice sprite with a texture file and a delimitation zone. The texture will be broken down into a 3×3 grid of equal blocks. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithFile: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 intract. It respects the anchorPoint too.

- (id)initWithFile:(NSString *)file rect:(CGRect)rect capInsets:(CGRect)capInsets

Parameters

file

The name of the texture file.

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.

capInsets

The values to use for the cap insets.

Discussion

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 intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithSpriteFrame:

Initializes a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

- (id)initWithSpriteFrame:(CCSpriteFrame *)spriteFrame

Parameters

spriteFrame

The sprite frame object.

Discussion

Initializes a 9-slice sprite with an sprite frame. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithSpriteFrame: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 intract. It respects the anchorPoint too.

- (id)initWithSpriteFrame:(CCSpriteFrame *)spriteFrame capInsets:(CGRect)capInsets

Parameters

spriteFrame

The sprite frame object.

capInsets

The values to use for the cap insets.

Discussion

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 intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithSpriteFrameName:

Initializes a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

- (id)initWithSpriteFrameName:(NSString *)spriteFrameName

Parameters

spriteFrameName

The sprite frame name.

Discussion

Initializes a 9-slice sprite with an sprite frame name. Once the sprite is created, you can then call its “setContentSize:” method to resize the sprite will all it’s 9-slice goodness intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

initWithSpriteFrameName: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 intract. It respects the anchorPoint too.

- (id)initWithSpriteFrameName:(NSString *)spriteFrameName capInsets:(CGRect)capInsets

Parameters

spriteFrameName

The sprite frame name.

capInsets

The values to use for the cap insets.

Discussion

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 intract. It respects the anchorPoint too.

Declared In

CCScale9Sprite.h

resizableSpriteWithCapInsets:

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.

- (CCScale9Sprite *)resizableSpriteWithCapInsets:(CGRect)capInsets

Parameters

capInsets

The values to use for the cap insets.

Discussion

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.

Declared In

CCScale9Sprite.h

setSpriteFrame:

Sets the sprite frame used to display the 9-slice sprite.

- (void)setSpriteFrame:(CCSpriteFrame *)spriteFrame

Parameters

spriteFrame

The new sprite frame.

Discussion

Sets the sprite frame used to display the 9-slice sprite.

Declared In

CCScale9Sprite.h