Public Member Functions | Static Public Member Functions | Properties

CCSprite Class Reference

#import "CCSprite.h"

Inherits CCNode, CCRGBAProtocol-p, and CCTextureProtocol-p.

Inherited by CCLabelTTF.

Collaboration diagram for CCSprite:
[legend]

List of all members.

Public Member Functions

(void) - addAnimation:
(CCAnimation *) - animationByName:
(CCSpriteFrame *) - displayedFrame
(id) - initWithBatchNode:rect:
(id) - initWithBatchNode:rectInPixels:
(id) - initWithCGImage:
(id) - initWithCGImage:key:
(id) - initWithFile:
(id) - initWithFile:rect:
(id) - initWithSpriteFrame:
(id) - initWithSpriteFrameName:
(id) - initWithTexture:
(id) - initWithTexture:rect:
(BOOL) - isFrameDisplayed:
(void) - setDisplayFrame:
(void) - setDisplayFrame:index:
(void) - setDisplayFrameWithAnimationName:index:
(void) - setTextureRect:
(void) - setTextureRectInPixels:rotated:untrimmedSize:
(void) - updateTransform
(void) - useBatchNode:
(void) - useSelfRender

Static Public Member Functions

(id) + spriteWithBatchNode:rect:
(id) + spriteWithCGImage:
(id) + spriteWithCGImage:key:
(id) + spriteWithFile:
(id) + spriteWithFile:rect:
(id) + spriteWithSpriteFrame:
(id) + spriteWithSpriteFrameName:
(id) + spriteWithTexture:
(id) + spriteWithTexture:rect:

Properties

NSUInteger atlasIndex
CCSpriteBatchNodebatchNode
ccBlendFunc blendFunc
ccColor3B color
BOOL dirty
BOOL flipX
BOOL flipY
ccHonorParentTransform honorParentTransform
CGPoint offsetPositionInPixels
GLubyte opacity
ccV3F_C4B_T2F_Quad quad
CCTextureAtlastextureAtlas
CGRect textureRect
BOOL textureRectRotated
BOOL usesBatchNode

Detailed Description

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).


Member Function Documentation

- (void) addAnimation: (CCAnimation *)  DEPRECATED_ATTRIBUTE  

adds an Animation to the Sprite.

Deprecated:
Use CCAnimationCache instead. Will be removed in 1.0.1
- (CCAnimation*) animationByName: (NSString *)  DEPRECATED_ATTRIBUTE  

returns an Animation given it's name.

Deprecated:
Use CCAnimationCache instead. Will be removed in 1.0.1
- (CCSpriteFrame*) displayedFrame  

returns the current displayed frame.

- (id) initWithBatchNode: (CCSpriteBatchNode *)  batchNode
rect: (CGRect)  rect 

Initializes an sprite with an CCSpriteSheet and a rect in points

- (id) initWithBatchNode: (CCSpriteBatchNode *)  batchNode
rectInPixels: (CGRect)  rect 

Initializes an sprite with an CCSpriteSheet and a rect in pixels

Since:
v0.99.5
- (id) initWithCGImage: (CGImageRef)  DEPRECATED_ATTRIBUTE  

Initializes an sprite with a CGImageRef

Deprecated:
Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
- (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: "sprite_frame_01". If key is nil, then a new texture will be created each time by the CCTextureCache.

Since:
v0.99.0
- (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.

Since:
v0.9
- (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. The offset will be (0,0).

- (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) setDisplayFrame: (NSString *)  animationName
index: (int)  DEPRECATED_ATTRIBUTE 

changes the display frame based on an animation and an index.

Deprecated:
Will be removed in 1.0.1. Use setDisplayFrameWithAnimationName:index instead
- (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

Since:
v0.99.5
- (void) setTextureRect: (CGRect)  rect  

updates the texture rect of the CCSprite in points.

- (void) setTextureRectInPixels: (CGRect)  rect
rotated: (BOOL)  rotated
untrimmedSize: (CGSize)  size 

updates the texture rect, rectRotated and untrimmed size of the CCSprite in pixels

+ (id) spriteWithBatchNode: (CCSpriteBatchNode *)  batchNode
rect: (CGRect)  rect 

Creates an sprite with an CCBatchNode and a rect

+ (id) spriteWithCGImage: (CGImageRef)  DEPRECATED_ATTRIBUTE  

Creates an sprite with a CGImageRef.

Deprecated:
Use spriteWithCGImage:key: instead. Will be removed in v1.0 final
+ (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: "sprite_frame_01". If key is nil, then a new texture will be created each time by the CCTextureCache.

Since:
v0.99.0
+ (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.

Since:
v0.9
+ (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.

- (void) useBatchNode: (CCSpriteBatchNode *)  batchNode  

tell the sprite to use sprite batch node

Since:
v0.99.0
- (void) useSelfRender  

tell the sprite to use self-render.

Since:
v0.99.0

Property Documentation

- (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

- (ccColor3B) color [read, write, assign]

RGB colors: conforms to CCRGBAProtocol 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;

- (ccHonorParentTransform) honorParentTransform [read, write, assign]

whether or not to transform according to its parent transfomrations. Useful for health bars. eg: Don't rotate the health bar, even if the parent rotates. IMPORTANT: Only valid if it is rendered using an CCSpriteBatchNode.

Since:
v0.99.0
- (CGPoint) offsetPositionInPixels [read, assign]

offset position in pixels of the sprite in points. Calculated automatically by editors like Zwoptex.

Since:
v0.99.0
- (GLubyte) opacity [read, write, assign]

opacity: conforms to CCRGBAProtocol protocol

- (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 rect of the CCSprite in points

- (BOOL) textureRectRotated [read, assign]

returns whether or not the texture rectangle is rotated

- (BOOL) usesBatchNode [read, write, assign]

whether or not the Sprite is rendered using a CCSpriteBatchNode


The documentation for this class was generated from the following file: