Music and timing-based games (note highways, tap rhythm games, rhythm action, one-button beat games). Syncing gameplay to the audio clock (AudioContext time, not frame time), beatmaps (charts) with BPM and offsets, note spawning ahead of time, judgment windows (perfect / great / good / miss), latency calibration, scoring, combos and accuracy, charting tools, music licensing, and touch-friendly ...
Download skill (.zip) Files on GitHubRhythm game development
Core: act on the beat. Everything depends on precise timing between audio, visuals and input.
Starter template
A playable starter for the game-scaffolding template is in assets/starter/. Four lanes timed from the AudioContext clock, a generated song (no audio files needed) scheduled ahead, a chart that gets denser, judgment windows, combo, accuracy and grade, an audio-offset setting, and audio that pauses with the game.
python3 <game-scaffolding>/scripts/scaffold.py my-game --title "My Game" --starter <this skill>/assets/starter
Controls: D F J K or arrows; - / = adjust the offset. Touch: tap the lane columns. Esc pauses. All numbers to tune are in src/config.js; the gameplay is in src/scenes/play.js.
Autoplay scored perfect hits, and pause stops the audio clock.
The one rule: use the audio clock
const ctx = new AudioContext(); // resumed on the first tap (game-sound-design)
const src = ctx.createBufferSource(); src.buffer = song; src.connect(ctx.destination);
const startAt = ctx.currentTime + 1.0; src.start(startAt);
const songTime = () => ctx.currentTime - startAt - calibration.offset; // seconds into the song: drive EVERYTHING from this
Never time notes with setTimeout or by counting frames: they drift. Positions are computed from songTime() every frame:
noteY = hitLineY - (note.time - songTime()) * scrollSpeed.
Charts (beatmaps)
const chart = { bpm: 120, offset: 0.08, notes: [{ t: 1.0, lane: 0 }, { t: 1.5, lane: 2 }, { t: 2.0, lane: 1, hold: 0.5 }] };
// beats → seconds: t = offset + beat * 60 / bpm
Chart by hand in a simple editor mode (play the song, tap keys to record times, quantize to 1/4 or 1/8 beats), or detect onsets roughly and clean up by hand. Store charts as JSON per difficulty.
Judgment
Compare the input time (taken from songTime() at the key/pointer event) with the nearest unjudged note in that lane:
| Judgment | Window (± ms) |
|---|---|
| Perfect | 35–45 |
| Great | 70–90 |
| Good | 110–135 |
| Miss | beyond, or the note passed |
Score = sum of judgments × combo multiplier; show accuracy %, max combo, a grade. Show judgment text and a hit burst on the lane.
Calibration
Players’ audio and input latency differ (Bluetooth headphones add 150+ ms). Add a calibration screen: tap to a metronome, set
offset to the average error; a separate visual offset. Save it.
Controls
Keyboard lanes (D F J K), touch lanes as big columns along the bottom (multi-touch with pointer IDs), gamepad buttons. Inputs handled in event handlers with timestamps converted to song time (don’t wait for the next frame).
Music
Only use music you have the rights to (your own, CC-licensed with credit: bash-game-audio-credits). Rhythm games are a common copyright problem.
Pitfalls
Frame-based timing, no calibration, judging on keyup, notes spawning on screen (spawn them before they’re visible), and
hidden-tab pauses desyncing (pause the AudioContext and the song together).