# Start a browser game with Phaser

A tiny Phaser 3 game with a local `ControllerHost`, QR lobby and two phone controllers. Move with the left stick or D-pad, dash with the bottom face button, and collect the gold disc. Scores survive a phone leaving and resuming.

**Tested:** Phaser 3.90.0, Node 22.22.0 and headless Chrome 156 on macOS arm64. Two browser phones exercised movement, dash, separate seats, feedback messages and reconnects. Real phones and physical feedback still need device checks.

## Contents

- [Install and run](#install-and-run)
- [See phone input](#see-phone-input)
- [Check two phones](#check-two-phones)
- [Use it in your game](#use-it-in-your-game)

## Install and run

Use the unpacked SDK archive, or a source checkout after `npm ci`. Keep `examples/phaser-arena` beside `examples/local-common`. From the SDK root, with Node 22 or newer:

```sh
node examples/phaser-arena/server.mjs
```

Open [the game and QR lobby](http://127.0.0.1:49700/). Phaser is loaded from the [exact 3.90.0 CDN URL](https://cdn.jsdelivr.net/npm/phaser@3.90.0/dist/phaser.min.js), with no build step. This is the starter's only extra runtime dependency. For offline use, download that file outside the checkout and set `PHASER_FILE` to its absolute path; the host serves it as `/phaser.js`.

## See phone input

For real phones on the same Wi-Fi, replace this example IP with the computer's reachable address:

```sh
PUBLIC_ORIGIN=http://192.168.1.20:49700 node examples/phaser-arena/server.mjs
```

Open the LAN URL on the shared display and scan its QR with both phones. Enter a name and tap **Play**. Move the left stick or D-pad: each phone moves its own circle. Collect the gold disc to increase its score. Tap the bottom face button to dash. Choose Gamepad in MENU if needed. See [shared setup](local-setup.md) for firewall/address checks and trusted local HTTPS for iPhone motion. This game needs only touch controls.

## Check two phones

```sh
node --test examples/phaser-arena/test.mjs
```

The test uses the SDK driver and two isolated phone pages in one installed headless Chrome. Real stick and dash touches collect a disc, move each assigned player, and deliver a cue and rumble with receipts. It checks leave, same-seat reload/resume, removal, invitation/QR rotation and process cleanup. Screenshots are optional; [capture settings and hardware limits](local-setup.md#scratch-files-and-captures) apply.

`server.mjs` owns the authoritative simulation; `client.mjs` draws its public snapshots with Phaser. `../local-common/runtime.mjs` contains the five lifecycle handlers. Type `remove p1` in the server terminal to free a seat. Ctrl+C stops the simulation and server.

## Use it in your game

Keep input and score under each `playerId`. Freeze input on `leave`; remove the game record on `removed`. This starter runs your own Node host and serves matching SDK files. It needs no desktop companion or hosted relay. For a static browser game using the hosted relay, use [Web games](web-games.md). Before release, read [Ship a game](shipping.md).

[All start pages](index.md) · [Search developer docs](search.md) · [Ship a game](shipping.md)
