Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sanchedev/tiny-engine/llms.txt
Use this file to discover all available pages before exploring further.
AnimationPlayer plays frame-based animations by calling a sequence of keyframe functions on each engine tick. Each keyframe function typically updates a sibling Sprite’s margin to display the correct frame from a sprite sheet. The player tracks the current frame index, advances it by fps × delta every update, and loops or ends the animation according to configuration.
Because keyframes often reference a sibling Sprite node, the animations prop is a deferred function — it is called when the node starts (not at construction time) so that other nodes in the scene tree are guaranteed to be initialized first.
Usage
Props
A function that returns a map of animation name → animation definition. The function is called once when the node starts, ensuring sibling nodes (like
Sprite) are available. Each animation definition is { fps: number, keyframes: AnimationKeyframe[], loop?: boolean }.The animation to play when the node starts. Pass a static string name to play a single animation immediately, or a
SignalGetter<string> to switch animations reactively whenever the signal changes.When
true, the node destroys itself automatically after the current non-looping animation ends. Ideal for one-shot effects like explosions or hit flashes. Defaults to false.A ref created by
useRefNode(PrimaryNode.AnimationPlayer). Exposes the AnimationPlayer instance so you can call play(), stop(), add(), and define() imperatively.Optional node identifier. Must match
[a-zA-Z][a-zA-Z0-9-_]* when a string.Events
Subscribe withuseEvent.
| Event name | Callback signature | Description |
|---|---|---|
animationChanged | (newAnim: string, oldAnim: string | null) => void | Fires when play() switches to a different animation. |
animationEnded | (anim: string) => void | Fires when a non-looping animation reaches its last frame. |
animationIndexChanged | (index: number) => void | Fires every time the frame index advances. |
animationStopped | (anim: string) => void | Fires when stop() is called. |
started | () => void | Fires once after the node starts and loads animations. |
updated | (delta: number) => void | Fires every frame during the update cycle. |
drawed | (delta: number) => void | Fires every frame during the draw cycle. |
destroyed | () => void | Fires once when the node is removed. |
Runtime methods
| Method | Description |
|---|---|
play(animName, index?) | Play the named animation, optionally starting from a specific frame index. |
stop() | Stop the current animation and reset the frame index to 0. |
setNext(animName | null) | Queue an animation to start automatically after the current one ends. |
add(animName, animation) | Register a single animation definition. Returns this for chaining. |
define(animations) | Register multiple animations at once. Returns this for chaining. |
Runtime properties
| Property | Type | Description |
|---|---|---|
currentAnim | string | null | Read-only. The name of the currently playing animation. |
index | number | Read-only. The current integer frame index. |
Reactive animation switching
Pass a computed signal tocurrentAnim to switch animations automatically based on game state:
One-shot effect example
The
animations prop must be a function, not an object literal. The function is invoked on start, at which point sibling nodes (such as Sprite) are already initialised and safe to reference.Related
- Animation guide —
kfFromSpriteSheet, custom keyframe functions, and sprite sheet layout Sprite— the texture node that keyframes typically updateuseSignal— create reactive state forcurrentAnimuseComputed— derive animation names from game state