49 lines
No EOL
2.6 KiB
HTML
49 lines
No EOL
2.6 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>enter — Ludic</title>
|
||
<meta name="description" content="The scene-entry hook — runs once as a scene becomes active.">
|
||
<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 & layers</a> <span>›</span> <span class="here">enter</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-keyword">keyword</span>
|
||
<h1 id="top">enter</h1>
|
||
</div>
|
||
<code class="sig">on enter { … }</code>
|
||
<div class="desc"><p><code>enter</code> names the body of a scene's entry hook, written <code>on enter { … }</code>. It runs <b>once</b> each time the scene becomes active — at boot for the <code>start</code> scene (right after the <code>Start</code> phase), and on every <code>become Name</code> that switches into it. This is where a scene builds what it owns: spawn its models, reset its counters, set the tilemap, open a menu. It is a lifecycle hook, not a phase, so it may not contain <code>phase</code> handlers; the scene's ongoing behaviour goes in its <code>layer</code> handlers instead.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program EnterHookExample {
|
||
property Position { column: int = 0, row: int = 0 }
|
||
model Player { Position }
|
||
|
||
var score: int = 0
|
||
|
||
scene Overworld start {
|
||
on enter {
|
||
score = 0
|
||
spawn Player { Position { column: 5, row: 5 } }
|
||
}
|
||
layer World {
|
||
handler DrawWorld phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
for (current_position) in query [Position, {Player}] {
|
||
Screen.fill_rectangle(x: current_position.column * 16, y: current_position.row * 16, 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> |