‹ Back to blog

Building a world from numbers instead of files

Most games, browser-based or otherwise, are made up of a lot of files. Sound effects are recorded audio clips. Textures are image files painted by hand or photographed. Music is a produced track. All of that has to be downloaded before a player can actually start playing, and for a game meant to load in a couple of seconds on a phone over an ordinary connection, every one of those files is a small tax against that goal.

There's a different approach, older than it might seem, that skips the files almost entirely: describe the sound or the image mathematically, and generate it in the player's own browser at the moment it's needed, rather than shipping a pre-made copy of it.

Sound made of numbers

Every browser has had access to something called the Web Audio API for years now, which lets a page generate raw audio waveforms directly in code — a rising tone, a soft chime, a burst of noise — without ever loading a sound file. As one simple illustration, a short "whoosh" effect can be built from a tone that slides upward in pitch over a fraction of a second, entirely defined by a formula rather than a recording. Small variations, like a note landing very slightly higher or lower each time, can be layered in cheaply this way too, without needing a library of pre-recorded variants.

The honest trade-off here is that these sounds are simpler than a professionally recorded and mixed sound effect would be — there's a real ceiling on how rich a mathematically generated tone can sound compared to sampled audio. What's gained in exchange is that the entire sound design for a game can add effectively nothing to its download size, since it's code, not audio files, and code compresses and loads far faster than audio ever does.

Textures drawn instead of loaded

The same idea extends to visuals. A building's windows, for instance, don't need to come from a photographed or hand-painted image file at all — they can be drawn onto a small canvas at the moment they're needed, using simple shapes in a handful of colors, and that drawing is then used directly as a surface texture. Because it's generated rather than loaded, introducing variation costs nothing extra: a pattern can be randomized on the spot, or even recalculated over time to reflect changing light, since it's just numbers being recalculated, not a different file being fetched.

Why this matters more for a browser game than almost anywhere else

This approach isn't really about being clever for its own sake. It's a direct response to what a browser game is actually competing against: the moment between someone clicking a link and deciding whether to bother waiting for it to load. A game with no external audio files and no downloaded image textures has very little standing between a player's tap and the first frame of actual gameplay, and in a genre built entirely around instant accessibility, that gap is close to the whole point.

Further reading on the techniques discussed in this post: