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 *)imageNameParameters
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)originalSizeParameters
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)originalSizeParameters
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)originalSizeParameters
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)originalSizeParameters
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 rectDeclared In
CCSpriteFrame.h
rotated
If YES, the frame rectangle is rotated.
@property (nonatomic, readonly) BOOL rotatedDeclared 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 offsetDeclared In
CCSpriteFrame.h
originalSize
Original size of the trimmed image, in points.
@property (nonatomic, readonly) CGSize originalSizeDeclared In
CCSpriteFrame.h
Texture Properties
texture
Texture used by the frame.
@property (nonatomic, strong, readonly) CCTexture *textureSee Also
Declared In
CCSpriteFrame.h
textureFilename
Texture image file name used to create the texture.
@property (nonatomic, strong, readonly) NSString *textureFilenameDeclared In
CCSpriteFrame.h