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>
34 lines
1.6 KiB
Markdown
34 lines
1.6 KiB
Markdown
---
|
|
id: tween-to
|
|
name: Tween.to
|
|
category: tween
|
|
kind: namespace-method
|
|
tokens: Tween.to
|
|
sig: Tween.to(from, to, dur, ease) -> handle
|
|
tip: Start a fluent, engine-advanced tween and return a handle.
|
|
order: 30
|
|
ns: Tween
|
|
member: to
|
|
---
|
|
|
|
Starts a <strong>stateful tween handle</strong> — from <code>from</code> to <code>to</code> over <code>dur</code> ticks with easing <code>ease</code> — and returns an integer handle. Unlike the pure <a href="tween-progress"><code>Tween.progress</code></a> interpolators (which the game drives from its own timer), a handle is <em>advanced by the engine</em> one tick per frame: fire it once, then read <a href="tween-value"><code>Tween.value</code></a> each frame and <a href="tween-done"><code>Tween.done</code></a> to know when it finishes. <a href="tween-chain"><code>Tween.chain</code></a> and <a href="tween-delay"><code>Tween.delay</code></a> append segments for a sequence. Integer and deterministic, so a sequence plays identically under replay. The handle pool is fixed-size and reuses finished slots.
|
|
|
|
Parameters:
|
|
- `from`, `to` — the start and end values (integer game units)
|
|
- `dur` — the segment length in engine ticks
|
|
- `ease` — 0 linear, 1 in, 2 out, 3 in-out
|
|
|
|
```ludic
|
|
program Demo {
|
|
property SpriteAnim { ticks: int = 0, fps: int = 0, frames: int = 0, mode: int = 0, frame: int = 0 }
|
|
property Pop { h: int = 0 }
|
|
model Coin { SpriteAnim, Pop }
|
|
entry {
|
|
spawn Coin { Pop { h: 0 } }
|
|
let e = World.query_next(World.prop_id("Pop"), 0)
|
|
let f = World.field_id(World.prop_id("Pop"), "h")
|
|
World.set(e, World.prop_id("Pop"), f, Tween.to(0, 40, 20, 2)) # pop upward
|
|
quit()
|
|
}
|
|
}
|
|
```
|