cocos2d-x  3.0-rc0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Animation Class Reference

A Animation object is used to perform animations on the Sprite objects. More...

#include <CCAnimation.h>

Inheritance diagram for Animation:
Ref Clonable

Public Member Functions

void addSpriteFrame (SpriteFrame *frame)
 Adds a SpriteFrame to a Animation. More...
 
void addSpriteFrameWithFile (const std::string &filename)
 Adds a frame with an image filename. More...
 
CC_DEPRECATED_ATTRIBUTE void addSpriteFrameWithFileName (const std::string &filename)
void addSpriteFrameWithTexture (Texture2D *pobTexture, const Rect &rect)
 Adds a frame with a texture and a rect. More...
 
float getTotalDelayUnits () const
 Gets the total Delay units of the Animation. More...
 
void setDelayPerUnit (float delayPerUnit)
 Sets the delay in seconds of the "delay unit". More...
 
float getDelayPerUnit () const
 Gets the delay in seconds of the "delay unit". More...
 
float getDuration () const
 Gets the duration in seconds of the whole animation. More...
 
const Vector< AnimationFrame * > & getFrames () const
 Gets the array of AnimationFrames. More...
 
void setFrames (const Vector< AnimationFrame * > &frames)
 Sets the array of AnimationFrames. More...
 
bool getRestoreOriginalFrame () const
 Checks whether to restore the original frame when animation finishes. More...
 
void setRestoreOriginalFrame (bool restoreOriginalFrame)
 Sets whether to restore the original frame when animation finishes. More...
 
unsigned int getLoops () const
 Gets the times the animation is going to loop. More...
 
void setLoops (unsigned int loops)
 Sets the times the animation is going to loop. More...
 
virtual Animationclone () const override
 returns a copy of the Ref More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Release the ownership immediately. More...
 
Refautorelease ()
 Release the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
- Public Member Functions inherited from Clonable
virtual ~Clonable ()
Refcopy () const
 returns a copy of the Ref. More...
 
var copy ()
 returns a copy of the Ref. More...
 
local copy ()
 returns a copy of the Ref. More...
 

Static Public Member Functions

static Animationcreate (void)
 Creates an animation. More...
 
static AnimationcreateWithSpriteFrames (const Vector< SpriteFrame * > &arrayOfSpriteFrameNames, float delay=0.0f)
static Animationcreate (const Vector< AnimationFrame * > &arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops=1)

Protected Member Functions

 Animation ()
virtual ~Animation (void)
bool init ()
 Initializes a Animation. More...
 
bool initWithSpriteFrames (const Vector< SpriteFrame * > &arrayOfSpriteFrameNames, float delay=0.0f)
 Initializes a Animation with frames and a delay between frames. More...
 
bool initWithAnimationFrames (const Vector< AnimationFrame * > &arrayOfAnimationFrameNames, float delayPerUnit, unsigned int loops)
 Initializes a Animation with AnimationFrame. More...
 
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Protected Attributes

float _totalDelayUnits
 total Delay units of the Animation. More...
 
float _delayPerUnit
 Delay in seconds of the "delay unit". More...
 
float _duration
 duration in seconds of the whole animation. More...
 
Vector< AnimationFrame * > _frames
 array of AnimationFrames More...
 
bool _restoreOriginalFrame
 whether or not it shall restore the original frame when the animation finishes More...
 
unsigned int _loops
 how many times the animation is going to loop. More...
 
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Detailed Description

A Animation object is used to perform animations on the Sprite objects.

The Animation object contains AnimationFrame objects, and a possible delay between the frames. You can animate a Animation object by using the Animate action. Example:

sprite->runAction(Animate::create(animation));

Constructor & Destructor Documentation

Animation ( )
protected
virtual ~Animation ( void  )
protectedvirtual

Member Function Documentation

void addSpriteFrame ( SpriteFrame frame)

Adds a SpriteFrame to a Animation.

The frame will be added with one "delay unit".

void addSpriteFrameWithFile ( const std::string &  filename)

Adds a frame with an image filename.

Internally it will create a SpriteFrame and it will add it. The frame will be added with one "delay unit". Added to facilitate the migration from v0.8 to v0.9.

CC_DEPRECATED_ATTRIBUTE void
addSpriteFrameWithFileName
( const std::string &  filename)
inline
void addSpriteFrameWithTexture ( Texture2D pobTexture,
const Rect rect 
)

Adds a frame with a texture and a rect.

Internally it will create a SpriteFrame and it will add it. The frame will be added with one "delay unit". Added to facilitate the migration from v0.8 to v0.9.

virtual Animation* clone ( ) const
overridevirtual

returns a copy of the Ref

Implements Clonable.

static Animation* create ( void  )
static

Creates an animation.

Since
v0.99.5
static Animation* create ( const Vector< AnimationFrame * > &  arrayOfAnimationFrameNames,
float  delayPerUnit,
unsigned int  loops = 1 
)
static
static Animation*
createWithSpriteFrames
( const Vector< SpriteFrame * > &  arrayOfSpriteFrameNames,
float  delay = 0.0f 
)
static
float getDelayPerUnit ( ) const
inline

Gets the delay in seconds of the "delay unit".

float getDuration ( ) const

Gets the duration in seconds of the whole animation.

It is the result of totalDelayUnits * delayPerUnit

const Vector<AnimationFrame*>
& getFrames
( ) const
inline

Gets the array of AnimationFrames.

unsigned int getLoops ( ) const
inline

Gets the times the animation is going to loop.

0 means animation is not animated. 1, animation is executed one time, ...

bool getRestoreOriginalFrame ( ) const
inline

Checks whether to restore the original frame when animation finishes.

float getTotalDelayUnits ( ) const
inline

Gets the total Delay units of the Animation.

bool init ( )
protected

Initializes a Animation.

bool initWithAnimationFrames ( const Vector< AnimationFrame * > &  arrayOfAnimationFrameNames,
float  delayPerUnit,
unsigned int  loops 
)
protected

Initializes a Animation with AnimationFrame.

Since
v2.0
bool initWithSpriteFrames ( const Vector< SpriteFrame * > &  arrayOfSpriteFrameNames,
float  delay = 0.0f 
)
protected

Initializes a Animation with frames and a delay between frames.

Since
v0.99.5
void setDelayPerUnit ( float  delayPerUnit)
inline

Sets the delay in seconds of the "delay unit".

void setFrames ( const Vector< AnimationFrame * > &  frames)
inline

Sets the array of AnimationFrames.

void setLoops ( unsigned int  loops)
inline

Sets the times the animation is going to loop.

0 means animation is not animated. 1, animation is executed one time, ...

void setRestoreOriginalFrame ( bool  restoreOriginalFrame)
inline

Sets whether to restore the original frame when animation finishes.

Member Data Documentation

float _delayPerUnit
protected

Delay in seconds of the "delay unit".

float _duration
protected

duration in seconds of the whole animation.

It is the result of totalDelayUnits * delayPerUnit

Vector<AnimationFrame*> _frames
protected

array of AnimationFrames

unsigned int _loops
protected

how many times the animation is going to loop.

0 means animation is not animated. 1, animation is executed one time, ...

bool _restoreOriginalFrame
protected

whether or not it shall restore the original frame when the animation finishes

float _totalDelayUnits
protected

total Delay units of the Animation.


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