Skip to content

Arcade games, touch controls and phones

Phase 5b added these (ADR 0025). Start from the template with pnpm create-game my-shooter --template arcade, or use Start from the arcade template in the platform editor.

Waves. A scene’s waves spawn groups of a prefab over time, entering from just above the view:

  • at: seconds after the scene starts.
  • count and every: how many, and the seconds between them.
  • x: a fraction of the view’s width, so it works at any screen width.
  • formation: column, line, v or random.
  • components: overrides for the spawned prefab.

wave:<n> is emitted when a wave starts, and waves:done once every wave has spawned and none of their entities is left.

Components:

  • Mover: moves by itself; no Body needed.
    • line: at (vx, vy).
    • sine and zigzag: sway sideways by amplitude every period seconds.
    • dive: drifts for delay seconds, then speeds toward where the player was.
  • Shooter: fires bullet prefabs rate times a second.
    • When: automatically, or while action is held.
    • Aim: up, down, or at the player.
    • Spread: count bullets over spread degrees.
  • Projectile: a bullet; it hurts the first entity with Health and targetTag that it touches, then disappears.
  • Score: adds points to a session counter (score) when its entity’s Health reaches 0, with an explosion.
  • Offscreen: removes entities that leave the view.
  • KeepInView: keeps the player on screen.
  • TopDownController: steers a ship in eight directions (the top-down controller).

Best scores. recordBest keeps the player’s best value ({ "value": "session.score", "key": "score" }, or lower: true for times). It is saved with the player’s saves: platform cloud saves when signed in, the browser otherwise. Bind it as best.score.

Backgrounds. A parallax layer with drift scrolls by itself, for starfields and clouds.

On phones and tablets (or with ?touch in the URL), games get on-screen controls. Without a touch section in game.json, they are made from the input actions:

  • moveX and moveY give a floating joystick;
  • moveX alone gives ◀ ▶ buttons;
  • jump, fire, interact, action, attack, dash and bomb give buttons;
  • pause gives a small corner button.

The controls hide while a menu is up, so taps reach the menu. In dialogue, choices can be tapped.

To choose the layout yourself:

"touch": {
"move": { "type": "joystick", "x": "moveX", "y": "moveY", "side": "left", "floating": true, "size": 110 },
"buttons": [{ "action": "fire", "label": "B", "side": "right" }],
"pause": "pause"
}

"enabled": false turns them off (for games played by tapping menus only).

With "display": { "width": 180, "height": 320, "scaleMode": "expand", "minWidth": 180, "maxWidth": 420 }, the view keeps its height and widens or narrows to the screen’s shape. The camera shows more or less world, and the HUD and menus anchor to the real edges, following rotations and resizes.

Without a follow target, the camera centres on the design area (width × height), so extra width appears on both sides. "orientation": "portrait" (or landscape) shows a “rotate your device” hint on phones held the other way.