How TETERI is built

Rendering: Sprite Caches and Layer Baking

Drawing four hundred glowing blocks per frame is slow. Drawing four hundred cached bitmaps is not.

Everything you see is drawn to a single canvas each frame. Making that fast required two specific optimisations, and measuring before and after.

The problem with drawing blocks honestly

Each block is a rounded rectangle with a three-stop vertical gradient, an inner bevel stroke and a specular highlight. Drawn properly that is a gradient object, several path operations and three fills, per block.

A full versus board is around four hundred blocks. Four hundred gradient allocations and twelve hundred path operations, sixty times a second, is a meaningful amount of work.

Sprite caching

The fix: cell size only changes when the layout changes. So each block face is drawn once into a small offscreen canvas per type and size, and the frame loop blits those bitmaps.

Four hundred gradient constructions become four hundred image draws, which the browser is extremely good at. The cache is cleared on resize and typically settles at fewer than ten entries.

The one exception is the active piece, whose glow pulses with its lock timer. That is a handful of cells, so it is drawn live.

Baking the overlays

The second cost was full-screen work: a vignette gradient, three additive nebula gradients, and scanlines drawn as three hundred one-pixel rectangles. All per frame.

The vignette and scanlines never change, so they are rendered once per resize into offscreen canvases and composited with a single image draw each.

The nebula does change, but slowly and blurrily, so it is rendered at a fifth of the resolution, refreshed a few times a second, and scaled up. Visually identical; a fraction of the fill cost.

The measurement

After both changes, the drawing work for a full versus board plus eight hundred particles measures about 2.4 milliseconds median, against a 16.7 millisecond budget for sixty frames a second. Roughly seven times the headroom needed.

That number is why the game runs smoothly on modest hardware.

PLAY TETERI ALL ARTICLES