diff --git a/game.js b/game.js index 6f1b069..3be3880 100644 --- a/game.js +++ b/game.js @@ -120,6 +120,13 @@ const SFX = (() => { return ctx; } + /* Resume AudioContext when user returns to the page on mobile */ + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible' && ctx && ctx.state === 'suspended') { + ctx.resume(); + } + }); + /* Core: play a tone with envelope */ function tone(freq, type, vol, attack, sustain, release, when) { const c = getCtx();