Skip to content

API / Animation

Class: Animation ​

Defined in: animation/Animation.ts:38

The animation player is used to play the animation data and manage the animation states.

Extends ​

Constructors ​

Constructor ​

ts
new Animation(): Animation;

Returns ​

Animation

Inherited from ​

BaseObject.constructor

Properties ​

hashCode ​

ts
readonly hashCode: number;

Defined in: core/BaseObject.ts:156

A unique identification number assigned to the object.

Inherited from ​

BaseObject.hashCode


timeScale ​

ts
timeScale: number;

Defined in: animation/Animation.ts:50

The play speed of all animations. [0: Stop, (0~1): Slow, 1: Normal, (1~N): Fast]

Default ​

ts
1.0

Accessors ​

animationConfig ​

Get Signature ​

ts
get animationConfig(): AnimationConfig;

Defined in: animation/Animation.ts:882

An AnimationConfig instance that can be used quickly.

Returns ​

AnimationConfig


animationNames ​

Get Signature ​

ts
get animationNames(): readonly string[];

Defined in: animation/Animation.ts:845

The name of all animation data

Returns ​

readonly string[]


animations ​

Get Signature ​

ts
get animations(): Record<string, AnimationData>;

Defined in: animation/Animation.ts:855

All animation data.

Returns ​

Record<string, AnimationData>

Set Signature ​

ts
set animations(value: Record<string, AnimationData>): void;

Defined in: animation/Animation.ts:858

Parameters ​
ParameterType
valueRecord<string, AnimationData>
Returns ​

void


isCompleted ​

Get Signature ​

ts
get isCompleted(): boolean;

Defined in: animation/Animation.ts:818

Check whether all the animation states' playing were finished.

Returns ​

boolean


isPlaying ​

Get Signature ​

ts
get isPlaying(): boolean;

Defined in: animation/Animation.ts:801

Check whether there is an animation state is playing

Returns ​

boolean


lastAnimationName ​

Get Signature ​

ts
get lastAnimationName(): string;

Defined in: animation/Animation.ts:835

The name of the last playing animation state.

Returns ​

string


lastAnimationState ​

Get Signature ​

ts
get lastAnimationState(): AnimationState;

Defined in: animation/Animation.ts:894

The last playing animation state

Returns ​

AnimationState

Methods ​

advanceTime() ​

ts
advanceTime(passedTime: number): void;

Defined in: animation/Animation.ts:168

Internal

Parameters ​

ParameterType
passedTimenumber

Returns ​

void


fadeIn() ​

ts
fadeIn(
   animationName: string, 
   fadeInTime: number, 
   playTimes: number, 
   layer: number, 
   group: string, 
   fadeOutMode: AnimationFadeOutMode): AnimationState;

Defined in: animation/Animation.ts:542

Fade in a specific animation.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
fadeInTimenumber-1.0The fade in time. [-1: Use the default value of animation data, [0~N]: The fade in time (In seconds)] (Default: -1)
playTimesnumber-1playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)
layernumber0The blending layer, the animation states in high level layer will get the blending weights with high priority, when the total blending weights are more than 1.0, there will be no more weights can be allocated to the other animation states. (Default: 0)
groupstringnullThe blending group name, it is typically used to specify the substitution of multiple animation states blending. (Default: null)
fadeOutModeAnimationFadeOutModeAnimationFadeOutMode.SameLayerAndGroupThe fade out mode, which is typically used to specify alternate mode of multiple animation states blending. (Default: AnimationFadeOutMode.SameLayerAndGroup)

Returns ​

AnimationState

The playing animation state.

Example ​

ts
    armature.animation.fadeIn("walk", 0.3, 0, 0, "normalGroup").resetToPose = false;
    armature.animation.fadeIn("attack", 0.3, 1, 0, "attackGroup").resetToPose = false;

getBlendState() ​

ts
getBlendState(
   type: string, 
   name: string, 
   target: BaseObject): BlendState;

Defined in: animation/Animation.ts:725

Internal

Parameters ​

ParameterType
typestring
namestring
targetBaseObject

Returns ​

BlendState


getState() ​

ts
getState(animationName: string, layer: number): AnimationState;

Defined in: animation/Animation.ts:757

Get a specific animation state.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation state.
layernumber-1The layer of find animation states. [-1: Find all layers, [0~N]: Specified layer] (default: -1)

Returns ​

AnimationState

Example ​

ts
    armature.animation.play("walk");
    let walkState = armature.animation.getState("walk");
    walkState.timeScale = 0.5;

getStates() ​

ts
getStates(): readonly AnimationState[];

Defined in: animation/Animation.ts:790

Get all the animation states.

Returns ​

readonly AnimationState[]


gotoAndPlayByFrame() ​

ts
gotoAndPlayByFrame(
   animationName: string, 
   frame: number, 
   playTimes: number): AnimationState;

Defined in: animation/Animation.ts:603

Play a specific animation from the specific frame.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
framenumber0The start frame of playing.
playTimesnumber-1Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)

Returns ​

AnimationState

The played animation state.


gotoAndPlayByProgress() ​

ts
gotoAndPlayByProgress(
   animationName: string, 
   progress: number, 
   playTimes: number): AnimationState;

Defined in: animation/Animation.ts:636

Play a specific animation from the specific progress.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
progressnumber0.0The start progress value of playing.
playTimesnumber-1Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)

Returns ​

AnimationState

The played animation state.


gotoAndPlayByTime() ​

ts
gotoAndPlayByTime(
   animationName: string, 
   time: number, 
   playTimes: number): AnimationState;

Defined in: animation/Animation.ts:574

Play a specific animation from the specific time.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
timenumber0.0The start time point of playing. (In seconds)
playTimesnumber-1Playing repeat times. [-1: Use the default value of animation data, 0: No end loop playing, [1~N]: Repeat N times] (Default: -1)

Returns ​

AnimationState

The played animation state.


gotoAndStopByFrame() ​

ts
gotoAndStopByFrame(animationName: string, frame: number): AnimationState;

Defined in: animation/Animation.ts:690

Stop a specific animation at the specific frame.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
framenumber0The stop frame.

Returns ​

AnimationState

The played animation state.


gotoAndStopByProgress() ​

ts
gotoAndStopByProgress(animationName: string, progress: number): AnimationState;

Defined in: animation/Animation.ts:714

Stop a specific animation at the specific progress.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
progressnumber0.0The stop progress value.

Returns ​

AnimationState

The played animation state.


gotoAndStopByTime() ​

ts
gotoAndStopByTime(animationName: string, time: number): AnimationState;

Defined in: animation/Animation.ts:666

Stop a specific animation at the specific time.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringundefinedThe name of animation data.
timenumber0.0The stop time. (In seconds)

Returns ​

AnimationState

The played animation state.


hasAnimation() ​

ts
hasAnimation(animationName: string): boolean;

Defined in: animation/Animation.ts:780

Check whether a specific animation data is included.

Parameters ​

ParameterTypeDescription
animationNamestringThe name of animation data.

Returns ​

boolean


init() ​

ts
init(armature: Armature): void;

Defined in: animation/Animation.ts:157

Internal

Parameters ​

ParameterType
armatureArmature

Returns ​

void


play() ​

ts
play(animationName: string, playTimes: number): AnimationState;

Defined in: animation/Animation.ts:483

Play a specific animation.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringnullThe name of animation data. (If not set, The default animation will be played, or resume the animation playing from pause status, or replay the last playing animation)
playTimesnumber-1Playing repeat times. [-1: Use default value of the animation data, 0: No end loop playing, [1~N]: Repeat N times] (default: -1)

Returns ​

AnimationState

The playing animation state.

Example ​

ts
    armature.animation.play("walk");

playConfig() ​

ts
playConfig(animationConfig: AnimationConfig): AnimationState;

Defined in: animation/Animation.ts:320

Beta

Play animation with a specific animation config. The API is still in the experimental phase and may encounter bugs or stability or compatibility issues when used.

Parameters ​

ParameterTypeDescription
animationConfigAnimationConfigThe animation config.

Returns ​

AnimationState

The playing animation state.


reset() ​

ts
reset(): void;

Defined in: animation/Animation.ts:272

Clear all animations states.

Returns ​

void


returnToPool() ​

ts
returnToPool(): void;

Defined in: core/BaseObject.ts:167

Clear the object and return it back to object pool。

Returns ​

void

Inherited from ​

BaseObject.returnToPool


stop() ​

ts
stop(animationName: string): void;

Defined in: animation/Animation.ts:292

Pause a specific animation state.

Parameters ​

ParameterTypeDefault valueDescription
animationNamestringnullThe name of animation state. (If not set, it will pause all animations)

Returns ​

void


borrowObject() ​

ts
static borrowObject<T>(objectConstructor: () => T): T;

Defined in: core/BaseObject.ts:136

Get an instance of the specify class from object pool.

Type Parameters ​

Type Parameter
T extends BaseObject

Parameters ​

ParameterTypeDescription
objectConstructor() => TThe specify class.

Returns ​

T

Inherited from ​

BaseObject.borrowObject


clearPool() ​

ts
static clearPool(objectConstructor: typeof BaseObject): void;

Defined in: core/BaseObject.ts:111

Clear the cached instances of a specify object pool.

Parameters ​

ParameterTypeDefault valueDescription
objectConstructortypeof BaseObjectnullSpecify class. (Clear all cached instances if not set)

Returns ​

void

Inherited from ​

BaseObject.clearPool


setMaxCount() ​

ts
static setMaxCount(objectConstructor: typeof BaseObject, maxCount: number): void;

Defined in: core/BaseObject.ts:72

Set the maximum cache count of the specify object pool.

Parameters ​

ParameterTypeDescription
objectConstructortypeof BaseObjectThe specify class. (Set all object pools max cache count if not set)
maxCountnumberMax count.

Returns ​

void

Inherited from ​

BaseObject.setMaxCount


toString() ​

ts
static toString(): string;

Defined in: animation/Animation.ts:39

Returns ​

string

Overrides ​

BaseObject.toString

Released under the MIT License.