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];
Tasks
Accessing Sprite Frame Attributes
-
rectproperty -
rotatedproperty -
offsetproperty -
originalSizeproperty -
textureproperty -
textureFilenameproperty
Creating a CCSpriteFrame Object
-
+ frameWithImageNamed: -
+ frameWithTexture:rectInPixels:rotated:offset:originalSize: -
+ frameWithTextureFilename:rectInPixels:rotated:offset:originalSize:
Initializing a CCSpriteFrame Object
Properties
offset
Offset of the frame in points. If it is updated, then offsetInPixels will also be updated.
@property (nonatomic, readonly) CGPoint offsetDeclared In
CCSpriteFrame.horiginalSize
Original size of the trimmed image in points.
@property (nonatomic, readonly) CGSize originalSizeDeclared In
CCSpriteFrame.hrect
Rectangle of the frame in points. If it is updated, then rectInPixels will also be updated.
@property (nonatomic, readonly) CGRect rectDeclared In
CCSpriteFrame.hrotated
Is the frame rectangle is rotated.
@property (nonatomic, readonly) BOOL rotatedDeclared In
CCSpriteFrame.htexture
Texture of the frame.
@property (nonatomic, strong, readonly) CCTexture *textureDeclared In
CCSpriteFrame.htextureFilename
Texture image file name, when created from a texture image.
@property (nonatomic, strong, readonly) NSString *textureFilenameDeclared In
CCSpriteFrame.hClass Methods
frameWithImageNamed:
Create and return a sprite frame object from the specified image name. On first attempt it will check CCSpriteFrameCache and if not available will then try and create from an image file of the same name.
+ (id)frameWithImageNamed:(NSString *)imageNameParameters
- imageName
Image name.
Return Value
The CCSpriteFrame Object.
Declared In
CCSpriteFrame.hframeWithTexture:rectInPixels:rotated:offset:originalSize:
Create and return a sprite frame object from the specified texture, texture rectangle, rotation status, offset and originalSize values.
+ (id)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.
Declared In
CCSpriteFrame.hframeWithTextureFilename: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.
+ (id)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.hInstance Methods
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.
Declared In
CCSpriteFrame.hinitWithTextureFilename: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