Animation
Per-clip animation state on nodes (node.animations[name]), blend layers, crossfade, events (including Blender timeline markers), drivers, and skeletal bone skinning. Animation data is loaded from .blend files via Resource.loadBlend.
AnimationState
Section titled “AnimationState”Obtained from node.animations[name]. Each named action from Blender appears as an entry. .events is a Map (event name → AnimationEvent).
Constructor
Section titled “Constructor”AnimationState.new() (typically obtained from node.animations[name]).
Time & params
Section titled “Time & params”| Method / property | Description |
|---|---|
name | Clip name (matches the Blender action name) |
length | Duration in seconds |
currentTimeSeconds / currentTimeNormalized | Current playback position |
getFloat(key) / setFloat(key, value) | Float param by short key or full Blender data path |
getInt(key) / setInt(key, value) | Int param |
getBool(key) / setBool(key, value) | Bool param |
Playback
Section titled “Playback”| Method | Description |
|---|---|
play(playOptions) | Start playing with optional AnimationPlayOptions |
pause() | Pause the clip |
resume() | Resume from paused |
events | Map of event name → AnimationEvent |
pendingEvents | List of events that fired this frame; dispatch in update(dt) |
Blend layers
Section titled “Blend layers”Multiple clips can play simultaneously on the same node using layers. Each clip is assigned a layer index and a blend weight.
| Property | Description |
|---|---|
blendWeight / blendWeight=(value) | This clip’s contribution (0–1, default 1.0) |
crossfadeTo(playOptions) | Smoothly crossfade from the current clip to a new one on the same layer |
stopLayer(layer) | Stop all clips on the given layer index |
// Play a walk animation on layer 0var walk = _node.animations["Walk"]var opts = AnimationPlayOptions.new()opts.loop = trueopts.layer = 0walk.play(opts)
// Crossfade to run when sprintingif (Input.key("shift")) { var runOpts = AnimationPlayOptions.new() runOpts.loop = true runOpts.layer = 0 runOpts.crossfadeDuration = 0.2 walk.crossfadeTo(runOpts)}Dispatching events
Section titled “Dispatching events”// In init():var anim = _node.animations["Attack"]anim.events["HitFrame"] = AnimationEvent.new()anim.events["HitFrame"].addCallback(Fn.new { |e| dealDamage()})
// In update(dt):for (event in anim.pendingEvents) { if (anim.events.containsKey(event.name)) { anim.events[event.name].invoke(event.name, event.time) }}AnimationEvent
Section titled “AnimationEvent”Named event slot (e.g. onStart, onEnd, or a Blender timeline marker). Create with AnimationEvent.new(), assign to animState.events["Name"], then register callbacks.
| Method / property | Description |
|---|---|
name | Event name |
time | Timestamp in seconds |
addCallback(callback) | Register a callback — Fn.new { |event| ... } |
removeCallback(callback) | Unregister a callback |
invoke(name, time) | Called when dispatching; invokes all registered callbacks |
AnimationPlayOptions
Section titled “AnimationPlayOptions”Options passed to play(playOptions) or crossfadeTo(playOptions) to configure how a clip starts.
Constructor
Section titled “Constructor”AnimationPlayOptions.new()
Properties
Section titled “Properties”| Property | Default | Description |
|---|---|---|
reverse / reverse=(value) | false | Play in reverse |
timeOffset / timeOffset=(value) | 0 | Start time offset in seconds |
speed / speed=(value) | 1 | Playback speed multiplier |
blendWeight / blendWeight=(value) | 1.0 | This clip’s blend contribution (0–1) |
layer / layer=(value) | 0 | Layer index for crossfade grouping |
crossfadeDuration / crossfadeDuration=(value) | 0 | Seconds to crossfade when replacing clips on the same layer |
loop / loop=(value) | false | Whether the clip loops |
var opts = AnimationPlayOptions.new()opts.loop = trueopts.speed = 1.5opts.blendWeight = 0.8opts.layer = 0_anim.play(opts)AnimationBlendOptions
Section titled “AnimationBlendOptions”Reserved for future blend tree support.
Constructor
Section titled “Constructor”AnimationBlendOptions.new()