Cocos2d-x  v4
Animation Class Reference

Inherits Ref, and 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...
 
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.
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor. More...
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()
 @js NA @lua NA
 

Static Public Member Functions

static Animationcreate ()
 Creates an animation. More...
 

Protected Member Functions

bool init ()
 Initializes a Animation.
 
bool initWithSpriteFrames (const Vector< SpriteFrame * > &arrayOfSpriteFrameNames, float delay=0.0f, unsigned int loops=1)
 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...
 

Additional Inherited Members

- Public Attributes inherited from Ref
unsigned int _ID
 object id, ScriptSupport need public _ID
 
int _luaID
 Lua reference id.
 
void * _scriptObject
 scriptObject, support for swift
 
bool _rooted
 When true, it means that the object was already rooted.
 

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

Member Function Documentation

◆ create()

static Animation* create ( )
static

Creates an animation.

Since
v0.99.5

◆ addSpriteFrame()

void addSpriteFrame ( SpriteFrame frame)

Adds a SpriteFrame to a Animation.

Parameters
frameThe frame will be added with one "delay unit".

◆ addSpriteFrameWithFile()

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.

Parameters
filenameThe path of SpriteFrame.

◆ addSpriteFrameWithTexture()

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.

Parameters
pobTextureA frame with a texture.
rectThe Texture of rect.

◆ getTotalDelayUnits()

float getTotalDelayUnits ( ) const
inline

Gets the total Delay units of the Animation.

Returns
The total Delay units of the Animation.

◆ setDelayPerUnit()

void setDelayPerUnit ( float  delayPerUnit)
inline

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

Parameters
delayPerUnitThe delay in seconds of the "delay unit".

◆ getDelayPerUnit()

float getDelayPerUnit ( ) const
inline

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

Returns
The delay in seconds of the "delay unit".

◆ getDuration()

float getDuration ( ) const

Gets the duration in seconds of the whole animation.

It is the result of totalDelayUnits * delayPerUnit.

Returns
Result of totalDelayUnits * delayPerUnit.

◆ getFrames()

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

Gets the array of AnimationFrames.

Returns
The array of AnimationFrames.

◆ setFrames()

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

Sets the array of AnimationFrames.

Parameters
framesThe array of AnimationFrames.

◆ getRestoreOriginalFrame()

bool getRestoreOriginalFrame ( ) const
inline

Checks whether to restore the original frame when animation finishes.

Returns
Restore the original frame when animation finishes.

◆ setRestoreOriginalFrame()

void setRestoreOriginalFrame ( bool  restoreOriginalFrame)
inline

Sets whether to restore the original frame when animation finishes.

Parameters
restoreOriginalFrameWhether to restore the original frame when animation finishes.

◆ getLoops()

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

Returns
The times the animation is going to loop.

◆ setLoops()

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

Parameters
loopsThe times the animation is going to loop.

◆ initWithSpriteFrames()

bool initWithSpriteFrames ( const Vector< SpriteFrame * > &  arrayOfSpriteFrameNames,
float  delay = 0.0f,
unsigned int  loops = 1 
)
protected

Initializes a Animation with frames and a delay between frames.

Since
v0.99.5

◆ initWithAnimationFrames()

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

Initializes a Animation with AnimationFrame.

Since
v2.0

The documentation for this class was generated from the following file:
cocos2d::Animate::create
static Animate * create(Animation *animation)
Creates the action with an Animation and will restore the original frame when the animation is over.