Skip to main content

Animation

Animation.

TypeNameInterface Description
Variablesduration: number

Function: total duration in seconds

VariablesendTime: number

Function: default end time for this animation

VariablesframeCount: number

Function: The frame count of the animation. Determined by the track with the highest number of frames. Enabling animation compression on import may reduce this value.

Variablesspeed: number

Function: set default playback speed for this animation

VariablesstartTime: number

Function: default start time for this animation

VariableswrapMode: AnimationWrapMode

Function: set default WrapMode for this animation

Functionsconstructor()

Examples

constructor()

let obj = new APJS.Animation();

Use Case

Example 1 — 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 {}
}

Example 2 — Object bounces up and down with a sine wave motion

@component()
export class BounceAnimation extends APJS.BasicScriptComponent {
private elapsed: number = 0;
private amplitude: number = 0.5;
private frequency: number = 2;
private startY: number = 0;

onStart(): void {
this.startY = this.getSceneObject().getTransform().localPosition.y;
}

onUpdate(deltaTime: number): void {
this.elapsed += deltaTime;
const offset = Math.sin(this.elapsed * this.frequency * Math.PI * 2) * this.amplitude;
const pos = this.getSceneObject().getTransform().localPosition;
this.getSceneObject().getTransform().localPosition = new APJS.Vector3f(pos.x, this.startY + offset, pos.z);
}
}
Copyright © 2026 TikTok. All rights reserved.
About TikTokHelp CenterCareersContactLegalTerms of ServicePrivacy PolicyCookies