Back to experiments
Canvas APIWeb AudioInteractive

Rebuilding the Chrome Dino Game in Canvas

By Hassam Sohail

When you're offline, Chrome turns a connection error into a game. I rebuilt it as a standalone version using HTML5 canvas, Web Audio and React.

Dino Runner
HI 0000000000

Press Space or Click to Jump

Keep the dinosaur safe! Relieve some developer tension right in the browser.

1. The 60FPS Canvas Game Loop

React state updates are designed for document lifecycles, not high-speed physics calculations. For smooth 60fps animation, I use the HTML5 <canvas> element combined with requestAnimationFrame.

A single loop handles physics (updating the dino's gravity and vertical velocity), procedural obstacle generation (cacti spacing), and collision bounding boxes in one thread, bypassing React's re-rendering overhead completely.

2. Zero-Asset Sound Synthesis

To keep the game self-contained, I synthesize the retro beeps in the browser with the Web Audio API. A virtual OscillatorNode changes frequency over a short interval, for example moving from 150Hz to 600Hz for a jump, so the game can produce square-wave audio without loading external MP3 files.

3. High-Score Persistence

I connected the score to localStorage, which lets the browser retain a personal best between sessions unless the site data is cleared. Test your reflexes and see how far you can run.