46 lines
No EOL
2.7 KiB
HTML
46 lines
No EOL
2.7 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Input — Ludic</title>
|
||
<meta name="description" content="The first per-frame phase — read the keyboard and record the player's intent.">
|
||
<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#phases">Phases</a> <span>›</span> <span class="here">Input</span></div>
|
||
<div class="item-head">
|
||
<span class="kind-badge kind-phase">phase</span>
|
||
<h1 id="top">Input</h1>
|
||
</div>
|
||
<code class="sig">phase Input</code>
|
||
<div class="desc"><p><code>Input</code> is the first phase of every frame. The runtime polls the keyboard just before it runs, so a <code>handler … phase Input</code> reads the current key with <code>Input.key()</code> and turns it into intent — a chosen direction, a menu selection, a pause toggle — usually by writing a program <code>var</code> that later phases act on. Keep it to <b>reading input and recording decisions</b>: do the actual movement and simulation in <code>FixedUpdate</code>/<code>Update</code>, and the drawing in <code>Render</code>. Because it runs before <code>FixedUpdate</code>, <code>Update</code>, <code>LateUpdate</code>, and <code>Render</code>, the intent it records is visible to every phase in the same frame.</p></div>
|
||
|
||
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program InputExample {
|
||
const DIRECTION_LEFT: int = 0
|
||
const DIRECTION_RIGHT: int = 1
|
||
var facing: int = DIRECTION_RIGHT
|
||
|
||
handler ReadControls phase Input {
|
||
let pressed_key = Input.key()
|
||
if pressed_key == 'a' { facing = DIRECTION_LEFT }
|
||
if pressed_key == 'd' { facing = DIRECTION_RIGHT }
|
||
}
|
||
|
||
handler DrawWorld phase Render {
|
||
Screen.clear(Color.MidnightBlue)
|
||
var marker_x = 40
|
||
if facing == DIRECTION_RIGHT { marker_x = 200 }
|
||
Screen.fill_rectangle(x: marker_x, y: 100, 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> |