![]() |
cocos2d-iphone
2.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
|
#import <CCSprite.h>
Public Member Functions | |
(id) | - initWithTexture: |
(id) | - initWithTexture:rect: |
(id) | - initWithTexture:rect:rotated: |
(id) | - initWithSpriteFrame: |
(id) | - initWithSpriteFrameName: |
(id) | - initWithFile: |
(id) | - initWithFile:rect: |
(id) | - initWithCGImage:key: |
(void) | - updateTransform |
(void) | - setTextureRect: |
(void) | - setTextureRect:rotated:untrimmedSize: |
(void) | - setVertexRect: |
(void) | - setDisplayFrame: |
(BOOL) | - isFrameDisplayed: |
(CCSpriteFrame *) | - displayFrame |
(void) | - setDisplayFrameWithAnimationName:index: |
(id) | - initWithBatchNode:rect: |
(CCSpriteFrame *) | - DEPRECATED_ATTRIBUTE |
Static Public Member Functions | |
(id) | + spriteWithTexture: |
(id) | + spriteWithTexture:rect: |
(id) | + spriteWithSpriteFrame: |
(id) | + spriteWithSpriteFrameName: |
(id) | + spriteWithFile: |
(id) | + spriteWithFile:rect: |
(id) | + spriteWithCGImage:key: |
(id) | + spriteWithBatchNode:rect: |
Protected Attributes | |
CCTextureAtlas * | _textureAtlas |
NSUInteger | _atlasIndex |
CCSpriteBatchNode * | _batchNode |
CGAffineTransform | _transformToBatch |
BOOL | _dirty |
BOOL | _recursiveDirty |
BOOL | _hasChildren |
BOOL | _shouldBeHidden |
ccBlendFunc | _blendFunc |
CCTexture2D * | _texture |
CGRect | _rect |
BOOL | _rectRotated |
CGPoint | _offsetPosition |
CGPoint | _unflippedOffsetPositionFromCenter |
ccV3F_C4B_T2F_Quad | _quad |
BOOL | _opacityModifyRGB |
BOOL | _flipX |
BOOL | _flipY |
Properties | |
BOOL | dirty |
ccV3F_C4B_T2F_Quad | quad |
NSUInteger | atlasIndex |
CGRect | textureRect |
BOOL | textureRectRotated |
BOOL | flipX |
BOOL | flipY |
CCTextureAtlas * | textureAtlas |
CCSpriteBatchNode * | batchNode |
CGPoint | offsetPosition |
ccBlendFunc | blendFunc |
CCSprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
CCSprite can be created with an image, or with a sub-rectangle of an image.
If the parent or any of its ancestors is a CCSpriteBatchNode then the following features/limitations are valid
If the parent is an standard CCNode, then CCSprite behaves like any other CCNode:
The default anchorPoint in CCSprite is (0.5, 0.5).
returns the current displayed frame.
- (id) initWithCGImage: | (CGImageRef) | image | |
key: | (NSString *) | key | |
Initializes an sprite with a CGImageRef and a key The key is used by the CCTextureCache to know if a texture was already created with this CGImage. For example, a valid key is: "_spriteframe_01". If key is nil, then a new texture will be created each time by the CCTextureCache.
- (id) initWithFile: | (NSString *) | filename |
Initializes an sprite with an image filename. The rect used will be the size of the image. The offset will be (0,0).
- (id) initWithFile: | (NSString *) | filename | |
rect: | (CGRect) | rect | |
Initializes an sprite with an image filename, and a rect. The offset will be (0,0).
- (id) initWithSpriteFrame: | (CCSpriteFrame *) | spriteFrame |
Initializes an sprite with an sprite frame.
- (id) initWithSpriteFrameName: | (NSString *) | spriteFrameName |
Initializes an sprite with an sprite frame name. An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name. If the CCSpriteFrame doesn't exist it will raise an exception.
- (id) initWithTexture: | (CCTexture2D *) | texture |
Initializes an sprite with a texture. The rect used will be the size of the texture. The offset will be (0,0).
- (id) initWithTexture: | (CCTexture2D *) | texture | |
rect: | (CGRect) | rect | |
Initializes an sprite with a texture and a rect in points (unrotated) The offset will be (0,0).
- (id) initWithTexture: | (CCTexture2D *) | texture | |
rect: | (CGRect) | rect | |
rotated: | (BOOL) | rotated | |
Initializes an sprite with a texture and a rect in points, optionally rotated. The offset will be (0,0). IMPORTANT: This is the designated initializer.
- (BOOL) isFrameDisplayed: | (CCSpriteFrame *) | frame |
returns whether or not a CCSpriteFrame is being displayed
- (void) setDisplayFrame: | (CCSpriteFrame *) | newFrame |
sets a new display frame to the CCSprite.
- (void) setDisplayFrameWithAnimationName: | (NSString *) | animationName | |
index: | (int) | frameIndex | |
changes the display frame with animation name and index. The animation name will be get from the CCAnimationCache
- (void) setTextureRect: | (CGRect) | rect |
set the texture rect of the CCSprite in points. It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.
- (void) setTextureRect: | (CGRect) | rect | |
rotated: | (BOOL) | rotated | |
untrimmedSize: | (CGSize) | size | |
set the texture rect, rectRotated and untrimmed size of the CCSprite in points. It will update the texture coordinates and the vertex rectangle.
- (void) setVertexRect: | (CGRect) | rect |
set the vertex rect. It will be called internally by setTextureRect. Useful if you want to create 2x images from SD images in Retina Display. Do not call it manually. Use setTextureRect instead.
+ (id) spriteWithCGImage: | (CGImageRef) | image | |
key: | (NSString *) | key | |
Creates an sprite with a CGImageRef and a key. The key is used by the CCTextureCache to know if a texture was already created with this CGImage. For example, a valid key is: "_spriteframe_01". If key is nil, then a new texture will be created each time by the CCTextureCache.
+ (id) spriteWithFile: | (NSString *) | filename |
Creates an sprite with an image filename. The rect used will be the size of the image. The offset will be (0,0).
+ (id) spriteWithFile: | (NSString *) | filename | |
rect: | (CGRect) | rect | |
Creates an sprite with an image filename and a rect. The offset will be (0,0).
+ (id) spriteWithSpriteFrame: | (CCSpriteFrame *) | spriteFrame |
Creates an sprite with an sprite frame.
+ (id) spriteWithSpriteFrameName: | (NSString *) | spriteFrameName |
Creates an sprite with an sprite frame name. An CCSpriteFrame will be fetched from the CCSpriteFrameCache by name. If the CCSpriteFrame doesn't exist it will raise an exception.
+ (id) spriteWithTexture: | (CCTexture2D *) | texture |
Creates an sprite with a texture. The rect used will be the size of the texture. The offset will be (0,0).
+ (id) spriteWithTexture: | (CCTexture2D *) | texture | |
rect: | (CGRect) | rect | |
Creates an sprite with a texture and a rect. The offset will be (0,0).
- (void) updateTransform |
updates the quad according the the rotation, position, scale values.
- (NSUInteger) atlasIndex [read, write, assign] |
The index used on the TextureAtlas. Don't modify this value unless you know what you are doing
- (CCSpriteBatchNode*) batchNode [read, write, assign] |
weak reference to the CCSpriteBatchNode that renders the CCSprite
- (ccBlendFunc) blendFunc [read, write, assign] |
conforms to CCTextureProtocol protocol
- (BOOL) dirty [read, write, assign] |
whether or not the Sprite needs to be updated in the Atlas
- (BOOL) flipX [read, write, assign] |
whether or not the sprite is flipped horizontally. It only flips the texture of the sprite, and not the texture of the sprite'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:
sprite.scaleX *= -1;
- (BOOL) flipY [read, write, assign] |
whether or not the sprite is flipped vertically. It only flips the texture of the sprite, and not the texture of the sprite'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:
sprite.scaleY *= -1;
- (CGPoint) offsetPosition [read, assign] |
offset position in points of the sprite in points. Calculated automatically by editors like Zwoptex.
- (ccV3F_C4B_T2F_Quad) quad [read, assign] |
the quad (tex coords, vertex coords and color) information
- (CCTextureAtlas*) textureAtlas [read, write, assign] |
weak reference of the CCTextureAtlas used when the sprite is rendered using a CCSpriteBatchNode
- (CGRect) textureRect [read, assign] |
returns the texture rect of the CCSprite in points
- (BOOL) textureRectRotated [read, assign] |
returns whether or not the texture rectangle is rotated