Cocos Creator API

1.0.0

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.

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

The animation to resumes, if not supplied then resumes all paused animations.

setCurrentTime
(
  • [time ]
  • [name ]
)

Make an animation named name go to the specified time. If no name is supplied then make all animations go to the specified time.

name type description
time optional Number

The time to go to

name optional String

Specified animation name, if not supplied then make all animations go to the time.

getAnimationState
(
  • name
)
AnimationState

Returns the animation state named name. If no animation with the specified name, the function will return null.

name type description
name String

returns:

addClip
(
  • clip
  • [newName ]
)
AnimationState

Adds a clip to the animation with name newName. If a clip with that name already exists it will be replaced with the new clip.

name type description
clip AnimationClip

the clip to add

newName optional String

returns:

type: AnimationState

The AnimationState which gives full control over the animation clip.

removeClip
(
  • clip
  • force
)

Remove clip from the animation list. This will remove the clip and any animation states based on it.

name type description
clip AnimationClip
force Boolean

If force is true, then will always remove the clip and any animation states based on it.

sample ( )

Samples animations at the current state.
This is useful when you explicitly want to set up some animation state, and sample it once.

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