The problem with most game “templates”
Open a marketplace game template and you usually get forty files, a package.json, a bundler, and a build command that fails on a newer Node. The game itself is maybe a tenth of that. You spend the first hour on configuration and the second on a dependency conflict, before you have changed a single pixel.
We went the other way. Five games — Stack Tower, Color Sort, Arrow Out, 2048 and Neon Dodge — in one folder of plain JavaScript files. No bundler, no framework, no CDN, no network request at runtime. Double-click index.html and they run, because a browser already knows how to run JavaScript.
The whole library is around 1,500 lines. That number is the feature: you can read every line before you trust it, and you can change behaviour without hunting through a dependency tree.
A game loop that does not depend on the frame rate
The common beginner loop calls update() once per animation frame and moves things by a constant. On a 120 Hz phone the game runs twice as fast as on a 60 Hz laptop. The fix is a fixed timestep: accumulate real elapsed time, and step the simulation in equal slices.
let acc = 0;
let last = performance.now();
const STEP = 1000 / 60; // simulate at 60 Hz regardless of the display
function frame(now) {
// cap the delta so a background tab does not fast-forward the game
acc += Math.min(now - last, 250);
last = now;
while (acc >= STEP) {
update(STEP / 1000);
acc -= STEP;
}
render();
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
Two details matter more than they look. The Math.min(..., 250) clamp keeps a tab that was asleep for ten minutes from simulating ten minutes of play in one burst. And update() takes seconds, not milliseconds, so gravity and speed constants read the way physics textbooks write them.
Sharp pixels on every screen
A canvas has two sizes: the CSS box it occupies and the pixel buffer behind it. Set the buffer to the CSS size and everything is soft on a high-DPI phone. Set it to the device pixel ratio and then forget to scale the drawing context, and your game renders in the top-left quarter of the screen.
function fit(canvas, ctx) {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const box = canvas.getBoundingClientRect();
canvas.width = Math.round(box.width * dpr);
canvas.height = Math.round(box.height * dpr);
// draw in CSS pixels; the browser handles the rest
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
}
window.addEventListener('resize', () => fit(canvas, ctx));
Capping the ratio at 2 is deliberate. A 3× buffer costs more than twice the fill rate for a difference nobody can see at arm's length, and it is the first thing that stutters on a mid-range Android phone.
One input path for mouse, finger and stylus
Older tutorials handle mousedown and touchstart separately, which is where double-fires and ghost clicks come from. Pointer events cover all three, and the coordinate maths is the same everywhere.
canvas.addEventListener('pointerdown', (e) => {
const box = canvas.getBoundingClientRect();
const x = e.clientX - box.left;
const y = e.clientY - box.top;
handleTap(x, y);
canvas.setPointerCapture(e.pointerId);
});
setPointerCapture is the line people forget. Without it, a finger that slides off the canvas stops producing events and the game keeps a stuck state until the next tap.
Levels you can regenerate instead of storing
Storing a hundred hand-made levels as JSON is fine until you want a hundred more. Seeding a small random generator with the level number gives you unlimited levels that are identical for every player, with no file to ship.
function rng(seed) {
return function next() {
seed = (seed + 0x6D2B79F5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const next = rng(42); // level 42 is the same board for everyone
const row = Math.floor(next() * 6);
This is the whole reason the games stay small: the data is code, and the code is twelve lines.
Progress without accounts
Every game keeps its best score and unlocked level in a single localStorage key. There is no sign-in, no sync, no server to keep alive, and nothing that fails when the connection drops. The trade is honest: progress does not follow you to a new phone. For a five-minute puzzle game, that is the right trade — most players never create the account anyway.
const key = 'stacktower.save';
const state = JSON.parse(localStorage.getItem(key) || '{"best":0,"level":1}');
localStorage.setItem(key, JSON.stringify(state));
Shipping the same files twice
Because the games are static files, hosting is a folder upload: GitHub Pages, Netlify, a subdirectory on a shared host. The path to Android is a WebView wrapper — Capacitor or a hand-written activity — pointing at the same index.html. The Play Store build adds a signed bundle, an icon set and a privacy policy, and the game code does not change.
That is the practical argument for no build step: one set of files serves the browser version, the demo and the app, and none of them can break because a dependency was published with a bad version on a Friday.
What it costs
Roughly 1,500 lines, five games, zero dependencies, and a first load well under 100 KB including the launcher page. The constraint is not minimalism for its own sake — it is that a small codebase stays fixable. A bug found in month six is a ten-minute change instead of an archaeology project.
If you would rather start from finished code
This is what the MD Nexa Game Kit is: the five games from this article, the same architecture, as a downloadable project with a launcher page, a shipping guide and a commercial licence. Unzip it, open index.html, and start changing the parts you care about.
Game Kit — $39, or $31.20 with code LAUNCH20
30-day refund. One-time price, commercial licence included.