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

56 lines
No EOL
2.9 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>scene — Ludic</title>
<meta name="description" content="A mutually-exclusive game state — a title screen, the overworld, a battle.">
<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#scenes">Scenes &amp; layers</a> <span>›</span> <span class="here">scene</span></div>
<div class="item-head">
<span class="kind-badge kind-keyword">keyword</span>
<h1 id="top">scene</h1>
</div>
<code class="sig">scene Name [start] { on enter{} on exit{} layer … }</code>
<div class="desc"><p>A <code>scene</code> is one of the mutually-exclusive states a game moves between — a title screen, the overworld, a battle, a shop. Exactly <b>one scene is active</b> at a time, and only the active scene's <code>layer</code> handlers run each phase; handlers declared outside any scene are global and run every frame regardless. A scene may carry an <code>on enter</code> / <code>on exit</code> pair of lifecycle hooks and one or more <code>layer</code> blocks that group its handlers. Under the hood a scene lowers to an implicit state machine the compiler writes for you (scenes number themselves by declaration order), so <code>become</code> from one scene to another costs two direct calls and a register store — no dispatch table.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program SceneExample {
var elapsed_frames: int = 0
scene Title start {
on enter { elapsed_frames = 0 }
layer Main {
handler WaitForStart phase Update {
elapsed_frames = elapsed_frames + 1
if Input.key() != 0 { become Overworld }
}
handler DrawTitle phase Render {
Screen.clear(Color.MidnightBlue)
Screen.draw_text(x: 60, y: 100, text: "PRESS ANY KEY", color: Color.White, scale: 1)
Screen.show()
}
}
}
scene Overworld {
on enter { elapsed_frames = 0 }
layer World {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.fill_rectangle(x: 80, y: 80, width: 16, height: 16, color: Color.LimeGreen)
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>