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>
35 lines
1.4 KiB
Markdown
35 lines
1.4 KiB
Markdown
---
|
|
id: anim-clip
|
|
name: Anim.clip
|
|
category: anim
|
|
kind: namespace-method
|
|
tokens: Anim.clip
|
|
sig: Anim.clip(name, frames, fps, mode)
|
|
tip: Register a named spritesheet clip so Anim.play can play it by name.
|
|
order: 31
|
|
ns: Anim
|
|
member: clip
|
|
---
|
|
|
|
Registers (or updates) a spritesheet clip under a <code>name</code>, so gameplay refers to a motion by name — <code>Anim.play(entity, "run")</code> — instead of repeating its frame count and rate everywhere. The clip stores <code>frames</code> (cell count), <code>fps</code> (rate) and <code>mode</code> (0 loop, 1 once, 2 ping-pong). Names compare by identity (a string literal interns to one pointer), and the registry holds up to 32 clips. Registering the same name again overwrites it.
|
|
|
|
Parameters:
|
|
- `name` — the clip name (a string)
|
|
- `frames` — number of cells in the clip
|
|
- `fps` — playback rate in frames per second
|
|
- `mode` — 0 loop, 1 once (clamp on last), 2 ping-pong
|
|
|
|
```ludic
|
|
program Demo {
|
|
property SpriteAnim { ticks: int = 0, fps: int = 0, frames: int = 0, mode: int = 0, frame: int = 0 }
|
|
model Hero { SpriteAnim }
|
|
entry {
|
|
Anim.clip("idle", 2, 4, 0) # a slow 2-frame idle loop
|
|
Anim.clip("run", 6, 12, 0) # a 6-frame run
|
|
Anim.clip("hit", 3, 15, 1) # a one-shot hit reaction
|
|
spawn Hero { SpriteAnim { } }
|
|
Anim.play(World.query_next(World.prop_id("SpriteAnim"), 0), "run")
|
|
quit()
|
|
}
|
|
}
|
|
```
|