Controller+BETADownload

Gamepad Demo

A free-play controller toy for one to four players. There is no countdown, time limit or losing screen. Each player runs a character around a small island, and every control does something you can see. Each player's card on the TV draws their controller: every control starts grey, takes its colour the first time it is used and glows while held, so anyone can check that every button, both sticks, the triggers and the D-pad work. Trying all of them (18 on a gamepad, 12 on a keyboard) sets off a celebration on the TV and a strong vibration on the phone. A beach ball sits in the middle; kick it through one of the two arches to score.

The module is examples/games/gamepad-demo.mjs, registered as gamepad-demo in GAMES and GAME_LIST. Its preferred and only phone mode is gamepad. It requests the full layout and fixes the face labels to the classic B/A/Y/X arrangement so the phone, TV and instructions agree. The phone shows a caption beside each control.

Control Effect
Left stick or D-pad Run
Right stick Aim: the eyes follow it and an arrow shows the direction
B / bottom button Jump; press again in the air to jump twice
A / right button Dash; kicks the ball hard and knocks other players aside
Y / left button New colour
X / top button Confetti, thrown where the right stick points
L / left shoulder Spin while held; a spin swats the ball
R / right shoulder Bubbles while held, toward the aim
L2 / R2 Jets. Each flame grows with its trigger; both together lift the character, higher the harder they are pressed
Press left / right stick Squish / wave
SELECT Back home, to where you started
START Pause or resume your character; the controller drawing stays live

On a phone, tap the centre of a stick to press it, or hold the centre to keep it pressed. Dragging still moves the stick.

The last action appears in a bubble over the character (for example "B: jump!") and on the phone's LCD, which also shows how many controls have been tried, goals, and both trigger values. Keyboard players see their own keys: arrows or WASD, Space, Shift, X, Y, Q, E, R and Enter.

Characters face where the left stick or D-pad sends them, including diagonals and dashes. L spins while held. On release, the character turns back to its movement heading within a quarter of a second.

A goal counts when the ball passes between an arch's posts; the last player to touch it scores, and the ball comes back to the middle. Characters and the ball stay on the island. A disconnected player's character stops and their input clears; reconnecting keeps their colour, position, goals and record of tried controls. Removing a player hides their character. No motion, camera or microphone permission is needed. Browser sound needs a user gesture, and vibration depends on the phone and browser. Ordinary phone gamepad triggers send on/off values; analog sources can send intermediate pressure.

Connect a host

Use the public host and pairing setup from the Node quickstart. Serve SDK assets with serveControllerAssets. After choosing the players:

import {createGame, restoreGame} from '@controller-plus/sdk/games';

const {module: game, state} = createGame('gamepad-demo', players, 42);
const binding = game.connect(host, state, {autoStart: false});
// From the host's existing loop:
binding.tick(1 / 60);
// Stop the binding before changing games:
binding.close();

const saved = JSON.parse(JSON.stringify(state));
const restored = restoreGame('gamepad-demo', saved);
// Reconnect restored.module to restored.state through the same public host API.

For the TV, use createScene(canvas) from examples/games/scene.mjs, call scene.push(state.public) when a snapshot arrives, then scene.start(). The scene loads the vendored Three.js renderer automatically. It renders WebGL offscreen and copies the result into the host's 2D canvas. Smooth character and ball motion uses the shared scene's snapshot interpolation. The renderer limits its internal 3D pixel count at larger TV sizes, and paints each card's controller outline once per size. No downloaded art, fonts, credentials or private service are required.

A host that already calls game.render(ctx, state.public, options) can continue doing so. The first call loads the renderer asynchronously. options.gameplayOnly: true omits the title and controller cards when making a card image. A host that composes the shared scene into its own canvas passes options.fx.draw; render then draws only that layer, because the scene has already drawn the game. Reuse createScene for a host that frequently switches games so its renderer lifecycle disposes graphics resources automatically.

Check it locally

Use Node 22 or newer and a source checkout: run npm ci, then npm test (includes TypeScript). No build step is needed. The focused test is:

node --test --test-concurrency=1 tests/gamepad-demo.test.mjs tests/gamepad-demo-browser.test.mjs

The browser test uses the installed Chrome in headless automation mode and a loopback-only host on port 49122. It opens real browser phones through the SDK test driver, sends real touches, tests all controls and reconnects, checks the drawn facing in eight directions after spin release and dashes, and checks that synthetic motion leaves this stick-and-button game alone. Set CHROME_PATH if Chrome is elsewhere. On machines needing software WebGL, point it to a wrapper that adds --use-angle=swiftshader --enable-unsafe-swiftshader.

Set GAMEPAD_DEMO_ARTIFACTS to an output folder to save TV images at 1280×720 and 1920×1080, phone images at 390×844 and 844×390, the input/feedback evidence and gamepad-demo-card.png at 1280×720. Browser automation verifies requested sound and vibration frames, not physical speaker or vibration output. Real devices and a TV are still needed to confirm those outputs and hardware frame rate.