kgames

KGames — free keyboard games for kids
git clone https://www.keyboard.games/code/kgames.git
Log | Files | Refs | README | LICENSE

commit c7565b6e5dd82825c507d06ce4ab321c58089855
parent 3ff6072bb4c3a95f57597d9c4cb800d110c24c6e
Author: Kyle Barlow <kb@kylebarlow.com>
Date:   Mon, 13 Jul 2026 19:06:41 -0700

fire-truck: start music on first keypress, not just pointer

Fire-truck is played entirely with the keyboard, so a player who
navigates to the page and immediately presses an arrow key never
triggers the pointerdown that gated audio init — music never started.
Init audio on the first keydown too (a real keydown is a user gesture
that satisfies the browser autoplay policy).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Diffstat:
Mgames/fire-truck/game.js | 4++++
1 file changed, 4 insertions(+), 0 deletions(-)

diff --git a/games/fire-truck/game.js b/games/fire-truck/game.js @@ -208,6 +208,10 @@ class FireTruckScene extends Phaser.Scene { this.input.keyboard.on('keydown', this.onKeyDown, this); this.input.keyboard.on('keyup', this.onKeyUp, this); + // This is a keyboard-driven game — players may never click the canvas, so + // start audio on the first key press too (a real keydown is a user gesture + // that satisfies the browser autoplay policy). + this.input.keyboard.once('keydown', () => this.initAudio(), this); this.input.once('pointerdown', () => this.initAudio(), this); this.scale.on('resize', this.onResize, this); this.onResize(this.scale.gameSize);