Skip to main content

Animator

Component that controls animation playback.

TypeNameInterface Description
Variablesanimations: Animation[]

Function: Gets the list of all animation resources associated with this animator. The returned array contains all animation resources that have been added to this animator.

Returns The array of animation resources.

Variablesplayback: Animation | null

Function: Gets the animation resource currently being played.

Returns The animation resource currently being played, or null if no animation is currently playing.

Functionsconstructor()

FunctionsgetAnimation(name: string): Animation

Function: Gets the animation resource with the specified name. The name must match an animation resource name associated with this animator.

Parameters

name: - The name of the animation resource to get.

Returns The animation resource with the specified name.

FunctionsgetEmitter(animationName: string): IEventEmitter | undefined

Function: Gets the event emitter for the specified animation. The animationName must match an animation resource name associated with this animator. Returns undefined if the animation does not exist or has no default clip.

FunctionsisPlaying(animationName: string): boolean

Function: Returns whether the specified animation is currently playing. The animationName must match an animation resource name associated with this animator.

Returns True if the specified animation is playing, otherwise false.

FunctionspauseAll(): void

Function: pause all animations playing in this animator

Functionsplay(animationName: string, wrapMode: number | AnimationWrapMode, speed: number, fadeInTime?: number): void

Function: Deprecated. Play animation exclusively in the default layer; use playback instead. The animationName must match an animation resource name associated with this animator.

Parameters

animationName: - animation's name

wrapMode: - loopCount or wrap mode, a value above 0 means loopCount

speed: - play speed

fadeTime: - blend weight fade duration, if is 0, do transition immediately

FunctionsresumeAll(): void

Function: resume all animations playing in this animator

FunctionsstopAll(): void

Function: stop all animations playing in this animator

Examples

animations: Animation[]

const anims = animator.animations;
console.log(anims.length);

playback: Animation | null

const current = animator.playback;
if (current) {
console.log(current.frameCount);
}

constructor()

let obj = new APJS.Animator();

getAnimation(name: string): Animation

const anim = animator.getAnimation('walk');
if (anim) {
animator.playback = anim;
}

isPlaying(animationName: string): boolean

const isPlaying = animator.isPlaying('animationName-walk');

pauseAll(): void

animator.pauseAll();

play(animationName: string, wrapMode: number | AnimationWrapMode, speed: number, fadeInTime?: number): void

animator.play('walk', AnimationWrapMode.Repeat, 1.0, 0.3);

resumeAll(): void

animator.resumeAll();

stopAll(): void

animator.stopAll();

Use Case

Control Animator with named animation clips: play idle/walk/run in Repeat mode, play wave/dance Once with auto-return to idle after duration.

@component()
export class CharacterAnimController extends APJS.BasicScriptComponent {
@serializeProperty
private animatorObject: APJS.SceneObject;

private animator: APJS.Animator;
private animations: APJS.Animation[] = [];
private idleReturnTimer: number = 0;

onStart(): void {
this.animator = this.animatorObject.getComponent("Animator") as APJS.Animator;
if (this.animator) {
this.animations = this.animator.animations;
}
}

private playAnimation(name: string, once: boolean = false): void {
if (!this.animator || this.animations.length === 0) return;
const anim = this.animations.find(a => a.name.toLowerCase().includes(name));
if (!anim) return;
// Skip if already playing this animation
if (this.animator.playback && this.animator.playback.name === anim.name) return;
if (once) {
this.animator.play(anim.name, APJS.AnimationWrapMode.Once, 1);
this.idleReturnTimer = anim.duration;
} else {
this.animator.play(anim.name, APJS.AnimationWrapMode.Repeat, 1);
}
}

onUpdate(deltaTime: number): void {
if (this.idleReturnTimer > 0) {
this.idleReturnTimer -= deltaTime;
if (this.idleReturnTimer <= 0) {
this.idleReturnTimer = 0;
this.playAnimation("idle");
}
}
}

onDestroy(): void {}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies