CCAnimation Class Reference

Inherits from NSObject
Conforms to NSCopying
Declared in CCAnimation.h

Overview

A CCAnimation is used to perform animations on a CCSprite.

The CCAnimation primarily contains a collection of CCAnimationFrame objects that contain information about individual animation frames.

Creating an Animation

+ animation

Creates and returns an animation object.

+ (instancetype)animation

Return Value

The CCAnimation Object.

Declared In

CCAnimation.h

+ animationWithSpriteFrames:

Creates and returns an animation object using the specified CCSpriteFrame array value. Default per frame delay of 1 second.

+ (instancetype)animationWithSpriteFrames:(NSArray *)arrayOfSpriteFrameNames

Parameters

arrayOfSpriteFrameNames

CCSpriteFrame array.

Return Value

The CCAnimation Object.

Declared In

CCAnimation.h

+ animationWithSpriteFrames:delay:

Creates and returns an animation object using the specified CCSpriteFrame array and per frame dealy values.

+ (instancetype)animationWithSpriteFrames:(NSArray *)arrayOfSpriteFrameNames delay:(float)delay

Parameters

arrayOfSpriteFrameNames

CCSpriteFrame array.

delay

Per frame delay (in seconds).

Return Value

The CCAnimation Object.

Declared In

CCAnimation.h

+ animationWithAnimationFrames:delayPerUnit:loops:

Creates and returns an animation object using the specified CCSpriteFrame array, per frame delay and times to repeat animation values.

+ (instancetype)animationWithAnimationFrames:(NSArray *)arrayOfAnimationFrames delayPerUnit:(float)delayPerUnit loops:(NSUInteger)loops

Parameters

arrayOfAnimationFrames

CCSpriteFrame array.

delayPerUnit

Per frame delay (in seconds).

loops

Number of times to repeat animation.

Return Value

The CCAnimation Object.

Declared In

CCAnimation.h

– initWithSpriteFrames:

Initializes and returns an animation object.

- (id)initWithSpriteFrames:(NSArray *)arrayOfSpriteFrameNames

Parameters

arrayOfSpriteFrameNames

CCSpriteFrame array.

Return Value

An initialized CCAnimation Object.

Declared In

CCAnimation.h

– initWithSpriteFrames:delay:

Initializes and returns an animation object using the specified CCSpriteFrame array and per frame dealy values.

- (id)initWithSpriteFrames:(NSArray *)arrayOfSpriteFrameNames delay:(float)delay

Parameters

arrayOfSpriteFrameNames

CCSpriteFrame array.

delay

Per frame delay (in seconds).

Return Value

An initialized CCAnimation Object.

Declared In

CCAnimation.h

– initWithAnimationFrames:delayPerUnit:loops:

Initializes and returns an animation object using the specified CCSpriteFrame array, per frame delay and times to repeat animation values.

- (id)initWithAnimationFrames:(NSArray *)arrayOfAnimationFrames delayPerUnit:(float)delayPerUnit loops:(NSUInteger)loops

Parameters

arrayOfAnimationFrames

CCSpriteFrame array.

delayPerUnit

Per frame delay (in seconds).

loops

Number of times to repeat animation.

Return Value

An initialized CCAnimation Object.

Declared In

CCAnimation.h

Adding Sprite Frames

– addSpriteFrame:

Add the specified sprite frame to the animation object.

- (void)addSpriteFrame:(CCSpriteFrame *)frame

Parameters

frame

CCSpriteFrame object.

See Also

Declared In

CCAnimation.h

– addSpriteFrameWithFilename:

Creates and adds a CCSpriteFrame to the animation object from the specified image file.

- (void)addSpriteFrameWithFilename:(NSString *)filename

Parameters

filename

Image file resource.

Declared In

CCAnimation.h

– addSpriteFrameWithTexture:rect:

Creates and adds a CCSpriteFrame to the animation object from the specified the texture and rectangle values.

- (void)addSpriteFrameWithTexture:(CCTexture *)texture rect:(CGRect)rect

Parameters

texture

Texture object.

rect

Rectangle to use.

See Also

Declared In

CCAnimation.h

Animation Timing

  totalDelayUnits

Total Delay units.

@property (nonatomic, readonly) float totalDelayUnits

Declared In

CCAnimation.h

  delayPerUnit

Delay in seconds of the per frame delay unit.

@property (nonatomic, readwrite) float delayPerUnit

Declared In

CCAnimation.h

  duration

Duration in seconds of the whole animation.

@property (nonatomic, readonly) float duration

Declared In

CCAnimation.h

  loops

Number of times to loop animation.

@property (nonatomic, readwrite) NSUInteger loops

Declared In

CCAnimation.h

Animation Frames

  frames

Array of CCAnimationFrames.

@property (nonatomic, readwrite, strong) NSMutableArray *frames

Declared In

CCAnimation.h

  restoreOriginalFrame

True to restore original frame when animation complete.

@property (nonatomic, readwrite) BOOL restoreOriginalFrame

Declared In

CCAnimation.h