ludic/kw-phase.html
2026-09-17 22:10:03 +00:00

58 lines
No EOL
3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>phase — Ludic</title>
<meta name="description" content="Names which stage of the frame a handler runs in.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#structure">Program structure</a> <span>›</span> <span class="here">phase</span></div>
<div class="item-head">
<span class="kind-badge kind-keyword">keyword</span>
<h1 id="top">phase</h1>
</div>
<code class="sig">phase Start | Input | Update | FixedUpdate | Render</code>
<div class="desc"><p>Every handler declares a <code>phase</code> — the stage of the frame in which the engine calls it. <b>Start</b> runs once at boot, before the first frame, and is where you seed the world. Then every frame the engine runs, in order, <b>Input</b> (read the keyboard), <b>FixedUpdate</b> (the deterministic fixed-timestep step, for physics and anything that must be reproducible), <b>Update</b> (the ordinary per-frame logic), and <b>Render</b> (draw the frame, ending with <code>Screen.show()</code>). Handlers in the same phase run in declaration order, so ordering within a phase is under your control. Put drawing only in <code>Render</code>; put keyboard reads in <code>Input</code>.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program PhaseTour {
property Position { column: int = 0, row: int = 0 }
property Velocity { delta_x: int = 0, delta_y: int = 0 }
model Player { Position, Velocity }
handler Boot phase Start {
spawn Hero { Position { column: 5, row: 5 } }
}
handler ReadKeys phase Input {
let pressed = Input.key()
for (velocity) in query [Velocity, {Player}] {
if pressed == 'd' { velocity.delta_x = 1 }
if pressed == 'a' { velocity.delta_x = -1 }
}
}
handler AdvancePositions phase Update {
for (position, velocity) in query [Position, Velocity, {Player}] {
position.column = position.column + velocity.delta_x
}
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
for (position) in query [Position, {Player}] {
Screen.fill_rectangle(x: position.column * 16, y: position.row * 16, width: 16, height: 16, color: Color.White)
}
Screen.show()
}
}</pre></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>