Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

Animation

Module: cc

The animation component is used to play back animations.

Animation provide several events to register:

  • play : Emit when begin playing animation
  • stop : Emit when stop playing animation
  • pause : Emit when pause animation
  • resume : Emit when resume animation
  • lastframe : If animation repeat count is larger than 1, emit when animation play to the last frame
  • finished : Emit when finish playing animation

Properties

defaultClip AnimationClip

Animation will play the default clip when start game.

currentClip AnimationClip

Current played clip.

_clips AnimationClip[] private

All the clips used in this animation.

playOnLoad Boolean

Whether the animation should auto play the default clip when start game.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

getClips ( ) AnimationClip[]

Get all the clips used in this animation.

returns:

play
(
  • [name ]
  • [startTime ]
)
AnimationState

Plays an animation and stop other animations.

name type description
name optional String

The name of animation to play. If no name is supplied then the default animation will be played.

startTime optional Number

play an animation from startTime

returns:

type: AnimationState

The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.

examples:

var animCtrl = this.node.getComponent(cc.Animation);
animCtrl.play("linear");

playAdditive
(
  • [name ]
  • [startTime ]
)
AnimationState

Plays an additive animation, it will not stop other animations. If there are other animations playing, then will play several animations at the same time.

name type description
name optional String

The name of animation to play. If no name is supplied then the default animation will be played.

startTime optional Number

play an animation from startTime

returns:

type: AnimationState

The AnimationState of playing animation. In cases where the animation can't be played (ie, there is no default animation or no animation with the specified name), the function will return null.

examples:

// linear_1 and linear_2 at the same time playing.
var animCtrl = this.node.getComponent(cc.Animation);
animCtrl.playAdditive("linear_1");
animCtrl.playAdditive("linear_2");

stop
(
  • [name ]
)

Stops an animation named name. If no name is supplied then stops all playing animations that were started with this Animation.
Stopping an animation also Rewinds it to the Start.

name type description
name optional String

The animation to stop, if not supplied then stops all playing animations.

pause
(
  • [name ]
)

Pauses an animation named name. If no name is supplied then pauses all playing animations that were started with this Animation.

name type description
name optional String

The animation to pauses, if not supplied then pauses all playing animations.

resume
(
  • [name ]
)

Resumes an animation named name. If no name is supplied then resumes all paused animations that were started with this Animation.

name type description
name optional String