Inherits from CCNodeRGBA : CCNode : NSObject
Conforms to CCRGBAProtocol
CCTextureProtocol
Declared in CCSprite.h

Overview

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

- Features when the parent is a CCBatchNode:
    - MUCH faster rendering, specially if the CCSpriteBatchNode has many children. All the children will be drawn in a single batch.

- Limitations
    - Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
    - GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
    - The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property.
    - The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property.
    - Parallax scroller is not supported, but can be simulated with a "proxy" sprite.

If the parent is an standard CCNode, then CCSprite behaves like any other CCNode: – It supports blending functions – It supports aliasing / antialiasing – But the rendering will be slower: 1 draw per children.

The default anchorPoint in CCSprite is (0.5, 0.5).

extends CCSprite

Tasks

Other Methods

  •   dirty

    whether or not the Sprite needs to be updated in the Atlas

    property
  •   quad

    the quad (tex coords, vertex coords and color) information

    property
  •   atlasIndex

    The index used on the TextureAtlas. Don’t modify this value unless you know what you are doing

    property
  •   textureRect

    returns the texture rect of the CCSprite in points

    property
  •   textureRectRotated

    returns whether or not the texture rectangle is rotated

    property
  •   flipX

    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:

    property
  •   flipY

    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:

    property
  •   textureAtlas

    weak reference of the CCTextureAtlas used when the sprite is rendered using a CCSpriteBatchNode

    property
  •   batchNode

    weak reference to the CCSpriteBatchNode that renders the CCSprite

    property
  •   offsetPosition

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

    property
  •   blendFunc

    conforms to CCTextureProtocol protocol

    property
  • + spriteWithTexture:

    Creates an sprite with a texture. The rect used will be the size of the texture. The offset will be (0,0).

  • + spriteWithTexture:rect:

    Creates an sprite with a texture and a rect. The offset will be (0,0).

  • + spriteWithSpriteFrame:

    Creates an sprite with an sprite frame.

  • + spriteWithSpriteFrameName:

    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.

  • + spriteWithFile:

    Creates an sprite with an image filename. The rect used will be the size of the image. The offset will be (0,0).

  • + spriteWithFile:rect:

    Creates an sprite with an image filename and a rect. The offset will be (0,0).

  • + spriteWithCGImage: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.

  • – initWithTexture:

    Initializes an sprite with a texture. The rect used will be the size of the texture. The offset will be (0,0).

  • – initWithTexture:rect:

    Initializes an sprite with a texture and a rect in points (unrotated) The offset will be (0,0).

  • – initWithTexture:rect: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.

  • – initWithSpriteFrame:

    Initializes an sprite with an sprite frame.

  • – initWithSpriteFrameName:

    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.

  • – initWithFile:

    Initializes an sprite with an image filename. The rect used will be the size of the image. The offset will be (0,0).

  • – initWithFile:rect:

    Initializes an sprite with an image filename, and a rect. The offset will be (0,0).

  • – initWithCGImage: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.

  • – updateTransform

    updates the quad according the the rotation, position, scale values.

  • – setTextureRect:

    set the texture rect of the CCSprite in points. It will call setTextureRect:rotated:untrimmedSize with rotated = NO, and utrimmedSize = rect.size.

  • – setTextureRect:rotated:untrimmedSize:

    set the texture rect, rectRotated and untrimmed size of the CCSprite in points. It will update the texture coordinates and the vertex rectangle.

  • – setVertexRect:

    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.

  • – setDisplayFrame:

    sets a new display frame to the CCSprite.

  • – isFrameDisplayed:

    returns whether or not a CCSpriteFrame is being displayed

  • – displayFrame

    returns the current displayed frame.

  • – setDisplayFrameWithAnimationName:index:

    changes the display frame with animation name and index. The animation name will be get from the CCAnimationCache

Other Methods

KoboldExtensions Methods

Deprecated Methods

Properties

atlasIndex

The index used on the TextureAtlas. Don’t modify this value unless you know what you are doing

@property (nonatomic, readwrite) NSUInteger atlasIndex

Declared In

CCSprite.h

batchNode

weak reference to the CCSpriteBatchNode that renders the CCSprite

@property (nonatomic, readwrite, assign) CCSpriteBatchNode *batchNode

Declared In

CCSprite.h

blendFunc

conforms to CCTextureProtocol protocol

@property (nonatomic, readwrite) ccBlendFunc blendFunc

Declared In

CCSprite.h

color

RGB colors: conforms to CCRGBAProtocol protocol

@property (nonatomic, readwrite) ccColor3B color

Declared In

CCSprite.h

dirty

whether or not the Sprite needs to be updated in the Atlas

@property (nonatomic, readwrite) BOOL dirty

Declared In

CCSprite.h

flipX

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:

@property (nonatomic, readwrite) BOOL flipX

Discussion

sprite.scaleX *= -1;

Declared In

CCSprite.h

flipY

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:

@property (nonatomic, readwrite) BOOL flipY

Discussion

sprite.scaleY *= -1;

Declared In

CCSprite.h

honorParentTransform

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

@property (nonatomic, readwrite) ccHonorParentTransform honorParentTransform

Availability

Declared In

CCSprite.h

offsetPosition

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

@property (nonatomic, readonly) CGPoint offsetPosition

Availability

Declared In

CCSprite.h

opacity

opacity: conforms to CCRGBAProtocol protocol

@property (nonatomic, readwrite) GLubyte opacity

Declared In

CCSprite.h

quad

the quad (tex coords, vertex coords and color) information

@property (nonatomic, readonly) ccV3F_C4B_T2F_Quad quad

Declared In

CCSprite.h

spriteSheet

weak reference to the CCSpriteSheet that renders the CCSprite

@property (nonatomic, readwrite, assign) CCSpriteSheet *spriteSheet

Declared In

CCSprite.h

textureAtlas

weak reference of the CCTextureAtlas used when the sprite is rendered using a CCSpriteBatchNode

@property (nonatomic, readwrite, assign) CCTextureAtlas *textureAtlas

Declared In

CCSprite.h

textureRect

returns the texture rect of the CCSprite in points

@property (nonatomic, readonly) CGRect textureRect

Declared In

CCSprite.h

textureRectRotated

returns whether or not the texture rectangle is rotated

@property (nonatomic, readonly) BOOL textureRectRotated

Declared In

CCSprite.h

usesSpriteSheet

whether or not the Sprite is rendered using a CCSpriteSheet

@property (nonatomic, readwrite) BOOL usesSpriteSheet

Declared In

CCSprite.h

Class Methods

spriteWithBatchNode:rect:

spriteWithCGImage:

Creates an sprite with a CGImageRef. (Deprecated: Use spriteWithCGImage:key: instead. Will be removed in v1.0 final)

+ (id)spriteWithCGImage:(CGImageRef)image

Declared In

CCSprite.h

spriteWithCGImage: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)spriteWithCGImage:(CGImageRef)image key:(NSString *)key

Availability

Declared In

CCSprite.h

spriteWithFile:

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

Declared In

CCSprite.h

spriteWithFile:rect:

Creates an sprite with an image filename and a rect. The offset will be (0,0).

+ (id)spriteWithFile:(NSString *)filename rect:(CGRect)rect

Declared In

CCSprite.h

spriteWithRenderTexture:

Creates an autoreleased sprite from a CCRenderTexture

+ (id)spriteWithRenderTexture:(CCRenderTexture *)rtx

Declared In

CCSpriteExtensions.h

spriteWithSpriteFrame:

Creates an sprite with an sprite frame.

+ (id)spriteWithSpriteFrame:(CCSpriteFrame *)spriteFrame

Declared In

CCSprite.h

spriteWithSpriteFrameName:

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)spriteWithSpriteFrameName:(NSString *)spriteFrameName

Availability

Declared In

CCSprite.h

spriteWithSpriteFrameNameOrFile:

First, checks if the string can be found in the spriteFrameCache, if not it will try to load the string assuming its a file name.

+ (id)spriteWithSpriteFrameNameOrFile:(NSString *)nameOrFile

Declared In

CCSpriteExtensions.h

spriteWithSpriteSheet:rect:

Creates an sprite with an CCSpriteSheet and a rect

+ (id)spriteWithSpriteSheet:(CCSpriteSheet *)spritesheet rect:(CGRect)rect

Declared In

CCSprite.h

spriteWithTexture:

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

Declared In

CCSprite.h

spriteWithTexture:rect:

Creates an sprite with a texture and a rect. The offset will be (0,0).

+ (id)spriteWithTexture:(CCTexture2D *)texture rect:(CGRect)rect

Declared In

CCSprite.h

spriteWithTexture:rect:offset:

Creates an sprite with a texture, a rect and offset.

+ (id)spriteWithTexture:(CCTexture2D *)texture rect:(CGRect)rect offset:(CGPoint)offset

Declared In

CCSprite.h

Instance Methods

addAnimation:

adds an Animation to the Sprite.

- (void)addAnimation:(CCAnimation *)animation

Declared In

CCSprite.h

animationByName:

returns an Animation given it’s name.

- (CCAnimation *)animationByName:(NSString *)animationName

Declared In

CCSprite.h

displayFrame

returns the current displayed frame.

- (CCSpriteFrame *)displayFrame

Declared In

CCSprite.h

displayedFrame

returns the current displayed frame.

- (CCSpriteFrame *)displayedFrame

Declared In

CCSprite.h

initWithBatchNode:rect:

initWithCGImage:

Initializes an sprite with a CGImageRef (Deprecated: Use spriteWithCGImage:key: instead. Will be removed in v1.0 final)

- (id)initWithCGImage:(CGImageRef)image

Declared In

CCSprite.h

initWithCGImage: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)initWithCGImage:(CGImageRef)image key:(NSString *)key

Availability

Declared In

CCSprite.h

initWithFile:

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

Declared In

CCSprite.h

initWithFile:rect:

Initializes an sprite with an image filename, and a rect. The offset will be (0,0).

- (id)initWithFile:(NSString *)filename rect:(CGRect)rect

Declared In

CCSprite.h

initWithSpriteFrame:

Initializes an sprite with an sprite frame.

- (id)initWithSpriteFrame:(CCSpriteFrame *)spriteFrame

Declared In

CCSprite.h

initWithSpriteFrameName:

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)initWithSpriteFrameName:(NSString *)spriteFrameName

Availability

Declared In

CCSprite.h

initWithSpriteSheet:rect:

Initializes an sprite with an CCSpriteSheet and a rect

- (id)initWithSpriteSheet:(CCSpriteSheet *)spritesheet rect:(CGRect)rect

Declared In

CCSprite.h

initWithTexture:

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

Declared In

CCSprite.h

initWithTexture: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

Declared In

CCSprite.h

initWithTexture:rect: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.

- (id)initWithTexture:(CCTexture2D *)texture rect:(CGRect)rect rotated:(BOOL)rotated

Declared In

CCSprite.h

isFrameDisplayed:

returns whether or not a CCSpriteFrame is being displayed

- (BOOL)isFrameDisplayed:(CCSpriteFrame *)frame

Declared In

CCSprite.h

playAnimAndRemoveWithFormat:numFrames:firstIndex:delay:animateTag:

Plays an anim once with the given file format (eg @“playeranim%i.png”) with the given number of frames and a starting index. The animateTag parameter is the tag given to the action playing the animation, so that you can stop it by tag. When the anim has cycled through all frames, the node running the animation will be removed from its parent. Useful for one-off animations, like an explosion, smoke-puff, blood splat, etc.

- (void)playAnimAndRemoveWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag

Declared In

CCSpriteExtensions.h

playAnimAndRemoveWithFormat:numFrames:firstIndex:delay:animateTag:restoreOriginalFrame:

Variant that allows to set the restoreOriginalFrame property.

- (void)playAnimAndRemoveWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag restoreOriginalFrame:(BOOL)restoreOriginalFrame

Declared In

CCSpriteExtensions.h

playAnimLoopedWithFormat:numFrames:firstIndex:delay:animateTag:

Plays an anim looped with the given file format (eg @“playeranim%i.png”) with the given number of frames and a starting index. The animateTag parameter is the tag given to the action playing the animation, so that you can stop it by tag.

- (void)playAnimLoopedWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag

Declared In

CCSpriteExtensions.h

playAnimLoopedWithFormat:numFrames:firstIndex:delay:animateTag:restoreOriginalFrame:

Variant that allows to set the restoreOriginalFrame property.

- (void)playAnimLoopedWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag restoreOriginalFrame:(BOOL)restoreOriginalFrame

Declared In

CCSpriteExtensions.h

playAnimWithFormat:numFrames:firstIndex:delay:animateTag:

Plays an anim once with the given file format (eg @“playeranim%i.png”) with the given number of frames and a starting index. The animateTag parameter is the tag given to the action playing the animation, so that you can stop it by tag.

- (void)playAnimWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag

Declared In

CCSpriteExtensions.h

playAnimWithFormat:numFrames:firstIndex:delay:animateTag:restoreOriginalFrame:

Variant that allows to set the restoreOriginalFrame property.

- (void)playAnimWithFormat:(NSString *)format numFrames:(int)numFrames firstIndex:(int)firstIndex delay:(float)delay animateTag:(int)animateTag restoreOriginalFrame:(BOOL)restoreOriginalFrame

Declared In

CCSpriteExtensions.h

setDisplayFrame:

sets a new display frame to the CCSprite.

- (void)setDisplayFrame:(CCSpriteFrame *)newFrame

Declared In

CCSprite.h

setDisplayFrame:index:

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

- (void)setDisplayFrame:(NSString *)animationName index:(int)frameIndex

Declared In

CCSprite.h

setDisplayFrameWithAnimationName:index:

changes the display frame with animation name and index. The animation name will be get from the CCAnimationCache

- (void)setDisplayFrameWithAnimationName:(NSString *)animationName index:(int)frameIndex

Availability

Declared In

CCSprite.h

setTextureRect:

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

Declared In

CCSprite.h

setTextureRect:rotated:untrimmedSize:

set the texture rect, rectRotated and untrimmed size of the CCSprite in points. It will update the texture coordinates and the vertex rectangle.

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

Declared In

CCSprite.h

setVertexRect:

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.

- (void)setVertexRect:(CGRect)rect

Declared In

CCSprite.h

updateTransform

updates the quad according the the rotation, position, scale values.

- (void)updateTransform

Declared In

CCSprite.h

useSelfRender

tell the sprite to use self-render.

- (void)useSelfRender

Availability

Declared In

CCSprite.h

useSpriteSheetRender:

tell the sprite to use sprite sheet render.

- (void)useSpriteSheetRender:(CCSpriteSheet *)spriteSheet

Availability

Declared In

CCSprite.h