Feature Library

Play input for couch and party games

0.28 CPU ms
A still of the Play input for couch and party games demo
Still
The live demo starts when it’s in view.Move with WASD, the arrows, a gamepad or a finger · Space dashes · stand on a pad to vote · R replays

The input and onboarding layer of a party game.

What it costs a frame

0.28 ms
GPU
not used
CPU, median
0.28 ms
CPU, 95th pct
0.49 ms
Draw calls
0
Weight
Light

Measured 15 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.24–0.36 ms). What ran: Measured with four bots from the first frame, starting at the practice: each frame runs exactly one 60 Hz tick (the run is uncapped, so real time would give a tick only every few frames), steps the twin machine from the encoded bytes, hashes both, and draws the field, the tokens, their trails and the lamps in Canvas 2D through the field camera. No GPU of its own. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring toolnot timed0.280.49
apple · Apple A19 Proin a browser tab · 16 November 2026not timed0.901.80
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 2026not timed0.420.82

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
Canvas 2DA 2D canvas: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages

What it’s for

  1. A couch or party game in the browser, where each seat may be keys, a gamepad or a phone
  2. Touch controls for any top-down or arena game: a stick wherever the thumb lands and a button beside it
  3. Button prompts that follow whatever the player picked up last
  4. A fixed-step game that can be networked in lockstep, checked against a second machine and replayed from its inputs
  5. Bots that play through the same messages a person would, so a lobby is never empty
  6. Onboarding by doing: a practice that ends once everyone has tried the action, and votes taken by standing on a pad
  7. A fixed 2D board or field fitted to any screen, turned for phones in portrait, with zoom and pinch

Pitfalls, in brief

  1. Sample each seat exactly once a tick (sample() clears the latch).
  2. A press is latched, not counted: two taps between the same two ticks are one press.
  3. Keys are read on keyTarget, window by default.
  4. The touch stick reads touch events where the browser has them (iOS Safari left a pointer-only stick dead), and pointers elsewhere.
  5. Determinism is yours to keep in step(): no Date, no Math.random, no Math.sin or other transcendental functions (engines may differ in the last bit), no iteration over objects whose key order can change.
8 more in brief
  1. Bots must keep their memory and random numbers outside the game state, or a replay fed only the recorded inputs will drift: the replay never calls them.
  2. The state must be plain data that structuredClone copies (the default clone): no class instances with methods, no DOM, no Maps keyed by objects.
  3. frame(ms) runs at most four ticks and drops the rest, so a stall never snowballs.
  4. The field camera works in the element’s own px: convert client coordinates (clientX minus the element’s left) before calling pinch() or zoomTo({ at }).
  5. Two fingers count as a pinch only if the second lands within 300 ms of the first and before the first has moved 18 px.
  6. Gamepads have no events: call poll() once a frame, even while the input is disabled (it then only watches, so a button held through a pause does not fire on resume).
  7. Disable the input (enabled = false) while the game is paused, as during a replay: presses made meanwhile are dropped, not saved up for the resume.
  8. Anything floating over the field (bars, a panel, the action button) must be kept clear through the camera’s insets (insetsAround picks the cheapest side for each), and drawing clipped to cam.clear, or a zoomed field runs under them.
13 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

mulberry32 (Tommy Ettinger): the seeded generator in rng.ts, as the source used it; public domain

Fowler–Noll–Vo hash (FNV-1a): the demo’s state hash that two machines compare

WAI-ARIA Authoring Practices Guide (W3C): the radio group pattern for the replay speed, and the application role on the play field

inputgame inputparty gamecouch multiplayerlocal multiplayerkeyboardgamepadGamepad APItouchvirtual stickfloating stickdevice switchinginput hintsbutton promptsinput latchfixed steplockstepdeterministicreplaynetcodebotsonboardingtutorialpractice round

Near it in the frame