feat(anim): animation ergonomics — named clips, Anim.play/Motion.to, frame events, fluent Tween handles (#48)
The ergonomic layer over the engine-owned SpriteAnim/Motion systems (#43): - Named clips: Anim.clip("run", frames, fps, mode) registers a clip by name and Anim.play(entity, "run") plays it; Anim.play(entity, fps, frames, mode) sets the clip directly. A name-keyed registry in systems.ludic. - Frame events: Anim.on_frame(entity, frame) arms optional SpriteAnim event_frame/event_fired fields; the engine flags the tick the clip first lands on that frame, and Anim.fired(entity) reads it — the game reacts, so it stays inside the no-runtime-dispatch event model. - Motion.to(entity, from, to, dur, ease) starts a value tween over the Motion component in one call (reflection-ABI writes, resetting the timer). - Fluent Tween handles (runtime/native/tween.ludic): Tween.to / Tween.chain / Tween.delay build a sequenced, disposable handle advanced by a new engine-owned system (esys_tween, run each Update tick); Tween.value / Tween.done / Tween.parallel / Tween.stop read and control it. The 1-arg Tween.done(handle) is disambiguated from the 2-arg pure Tween.done(timer, dur). Splicing: g_uses_anim_rt pulls in systems.ludic; g_uses_tween_rt pulls in tween.ludic and inserts esys_tween into the Update phase. All integer and deterministic, so animation and motion reproduce exactly under replay/lockstep. Worked example + regression: examples/library/anim_sugar.ludic (4 8 2 1 0 100 100 0 0 1 20 20 30 0 1). Twelve new docs pages (Anim, the new Motion namespace, Tween handles). Full suite 77 passed, self-host C-free fixpoint intact, no golden drift. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
382826889f
commit
1f5e3c1c1a
25 changed files with 24149 additions and 21866 deletions
33
docs/language/anim/anim-on_frame.md
Normal file
33
docs/language/anim/anim-on_frame.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
id: anim-on_frame
|
||||
name: Anim.on_frame
|
||||
category: anim
|
||||
kind: namespace-method
|
||||
tokens: Anim.on_frame
|
||||
sig: Anim.on_frame(entity, frame)
|
||||
tip: Arm a frame event — the engine flags the tick a clip lands on this frame.
|
||||
order: 32
|
||||
ns: Anim
|
||||
member: on_frame
|
||||
---
|
||||
|
||||
Arms a <strong>frame event</strong> on an entity's <code>SpriteAnim</code>: the engine sets the component's <code>event_fired</code> flag on the tick the clip <em>first lands</em> on <code>frame</code> — a footstep on the contact cell, a hitbox going live mid-swing. Gameplay reads the flag with <a href="anim-fired"><code>Anim.fired</code></a> in its own handler and reacts (emit its own event, spawn, play a sound). The engine detects the boundary; the game owns the reaction, so it stays inside the deterministic, no-runtime-dispatch event model. Requires the component to carry <code>event_frame</code> and <code>event_fired</code> fields.
|
||||
|
||||
Parameters:
|
||||
- `entity` — the entity carrying `SpriteAnim`
|
||||
- `frame` — the cell index that should fire the event
|
||||
|
||||
```ludic
|
||||
program Demo {
|
||||
property SpriteAnim { ticks: int = 0, fps: int = 0, frames: int = 0, mode: int = 0, frame: int = 0, event_frame: int = 0, event_fired: int = 0 }
|
||||
model Hero { SpriteAnim }
|
||||
entry {
|
||||
spawn Hero { SpriteAnim { fps: 12, frames: 6, mode: 0 } }
|
||||
let e = World.query_next(World.prop_id("SpriteAnim"), 0)
|
||||
Anim.on_frame(e, 3) # fire when the run clip hits its contact frame
|
||||
tick_fixed()
|
||||
if Anim.fired(e) { print(1) }
|
||||
quit()
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue