1The loop, and the trap of time
Every real-time game is a loop: read the inputs β update the state β draw, again and again. The subtlety lives in βupdateβ.
If you move an object by a fixed number of pixels each frame, its speed depends on the frame rate: twice as fast on a 120 Hz screen as on a 60 Hz one. The fix is the timestep (dt): we multiply each movement by the time that actually elapsed, in seconds.
update(time, delta) { const dt = delta / 1000; // ms β s x += speed * dt; // the same real speed everywhere }
2Scenes: a state machine
Phaser organises the game into scenes. Seen from higher up, it's a finite state machine: at any moment one scene is active, and explicit transitions lead from one to another.
Each scene has a clear life cycle: init (receive data), create (build the display), update (every frame), and a SHUTDOWN where we clean up (remove listeners, DOM elements). Forgetting that cleanup is a guaranteed memory leak whenever you move from one scene to another.
3The big idea: simulation β rendering
The project's most important decision: the core of the game does not know about Phaser. All the logic β trajectories, collisions, wind, score β lives in src/sim/, in plain JavaScript, with no graphics dependency whatsoever.
- π§
src/sim/β the simulation: what is happening? (can run under Node, with no browser) - π¨
src/scenes/,src/objects/β the rendering: what does it look like? - βοΈ
src/config/β the data: settings and themes, kept apart from the code.
4Docker, seen as a reproducible boundary
The Dockerfile is multi-stage for an architectural reason: to separate build time from run time. The first stage installs all the tooling and compiles; the second keeps only the bare minimum needed to run.
# stage 1: build (needs the whole toolchain) FROM node:24-alpine AS build RUN npm ci && npm run build # stage 2: run (slim, prod deps only) FROM node:24-alpine RUN npm ci --omit=dev COPY --from=build /app/dist ./dist
The result: a smaller image, with no compilers or development dependencies in production. The same logic drives the server bundle (zip / tar.gz) added in v1.1.0: ship only dist/, server/ and the shared simulation.