wobblyhead hg > minor_monsters
diff game/js/main.js @ 32:85d23328a215 0.10.0
added intro music, logic for browser audio triggering on splash screen
| author | ark |
|---|---|
| date | 2026-10-20 18:39 +0200 |
| parents | 75deda08db90 |
| children |
line wrap: on
line diff
--- a/game/js/main.js Tue Oct 20 17:58:10 2026 +0200 +++ b/game/js/main.js Tue Oct 20 18:39:22 2026 +0200 @@ -28,14 +28,27 @@ resize(); } - // the splash screen over the paused first map - function splash() { + // the splash screen over the paused first map, with the intro music. + // browsers start sound only in a user interaction, so on the first + // splash screen, unless sound is switched off, a sound button covers + // the play button until it is tapped. sound is unlocked when the + // splash screen returns after a won game. + function splash(first) { startMap(FIRST); game.splash = true; game.paused = true; + if (first && MM.audio.enabled()) game.askSound = true; + else MM.audio.playMusic("intro"); + } + + function startSound() { + MM.audio.start(); + game.askSound = false; + MM.audio.playMusic("intro"); } function play() { + MM.audio.stopMusic(); game.splash = false; game.paused = false; } @@ -89,14 +102,15 @@ view: view, game: function () { return game; }, layout: function () { return L; }, + startSound: startSound, play: play, next: function () { startMap(game.map.index + 1); }, retry: function () { startMap(FIRST); }, - restart: splash + restart: function () { splash(false); } }); MM.assets.load(function (failed) { if (failed.length) console.error("images not loaded:", failed); - splash(); + splash(true); requestAnimationFrame(frame); }); })();
