CCSpriteFrame Class Reference

Inherits from NSObject
Conforms to NSCopying
Declared in CCSpriteFrame.h

Overview

A CCSpriteFrame contains the texture and rectangle of the texture to be used by a CCSprite.

You can easily modify the sprite frame of a CCSprite using the following handy method:

CCSpriteFrame *frame = [CCSpriteFrame frameWithImageNamed:@"jump.png"];
[sprite setSpriteFrame:frame];

Creating a Sprite Frame

+ frameWithImageNamed:

Create and return a sprite frame object from the specified image name. On first attempt it will check the internal texture/frame cache and if not available will then try and create the frame from an image file of the same name.

+ (instancetype)frameWithImageNamed:(NSString *)imageName

Parameters

imageName

Image name.

Return Value

The CCSpriteFrame Object.

Declared In

CCSpriteFrame.h

+ frameWithTexture:rectInPixels:rotated:offset:originalSize:

Create and return a sprite frame object from the specified texture, texture rectangle, rotation status, offset and originalSize values.

+ (instancetype)frameWithTexture:(CCTexture *)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize

Parameters

texture

Texture to use.

rect

Texture rectangle (in pixels) to use.

rotated

Is rectangle rotated?

offset

Offset (in pixels) to use.

originalSize

Original size (in pixels) before being trimmed.

Return Value

The CCSpriteFrame Object.

See Also

Declared In

CCSpriteFrame.h

+ frameWithTextureFilename:rectInPixels:rotated:offset:originalSize:

Create and return a sprite frame object from the specified texture file name, texture rectangle, rotation status, offset and originalSize values.

+ (instancetype)frameWithTextureFilename:(NSString *)filename rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize

Parameters

filename

Image file name to use.

rect

Texture rectangle (in pixels) to use.

rotated

Is rectangle rotated?

offset

Offset (in pixels) to use.

originalSize

Original size (in pixels) before being trimmed.

Return Value

The CCSpriteFrame Object.

Declared In

CCSpriteFrame.h

– initWithTexture:rectInPixels:rotated:offset:originalSize:

Initializes and returns a sprite frame object from the specified texture, texture rectangle, rotation status, offset and originalSize values.

- (id)initWithTexture:(CCTexture *)texture rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize

Parameters

texture

Texture to use.

rect

Texture rectangle (in pixels) to use.

rotated

Is rectangle rotated?

offset

Offset (in pixels) to use.

originalSize

Original size (in pixels) before being trimmed.

Return Value

An initialized CCSpriteFrame Object.

See Also

Declared In

CCSpriteFrame.h

– initWithTextureFilename:rectInPixels:rotated:offset:originalSize:

Initializes and returns a sprite frame object from the specified texture file name, texture rectangle, rotation status, offset and originalSize values.

- (id)initWithTextureFilename:(NSString *)filename rectInPixels:(CGRect)rect rotated:(BOOL)rotated offset:(CGPoint)offset originalSize:(CGSize)originalSize

Parameters

filename

Image file name to use.

rect

Texture rectangle (in pixels) to use.

rotated

Is rectangle rotated?

offset

Offset (in pixels) to use.

originalSize

Original size (in pixels) before being trimmed.

Return Value

An initialized CCSpriteFrame Object.

Declared In

CCSpriteFrame.h

Sprite Frame Properties

  rect

Rectangle of the frame within the texture, in points. If it is updated, then rectInPixels will also be updated.

@property (nonatomic, readonly) CGRect rect

Declared In

CCSpriteFrame.h

  rotated

If YES, the frame rectangle is rotated.

@property (nonatomic, readonly) BOOL rotated

Declared In

CCSpriteFrame.h

  offset

Offset of the frame from the texture’s origin, in points. If it is updated, then offsetInPixels will also be updated.

@property (nonatomic, readonly) CGPoint offset

Declared In

CCSpriteFrame.h

  originalSize

Original size of the trimmed image, in points.

@property (nonatomic, readonly) CGSize originalSize

Declared In

CCSpriteFrame.h

Texture Properties

  texture

Texture used by the frame.

@property (nonatomic, strong, readonly) CCTexture *texture

See Also

Declared In

CCSpriteFrame.h

  textureFilename

Texture image file name used to create the texture.

@property (nonatomic, strong, readonly) NSString *textureFilename

Declared In

CCSpriteFrame.h