22 lines
759 B
JavaScript
22 lines
759 B
JavaScript
// Menu music spans Intro -> MainMenu -> LevelSelect as one continuous track
|
|
// (Phaser's sound manager lives on the game, not the scene, so a Sound
|
|
// object started in one scene keeps playing through scene.start() calls
|
|
// into the next). playMenuMusic is safe to call from every one of those
|
|
// scenes' create() - it no-ops if the track is already playing so
|
|
// navigating between them doesn't restart it.
|
|
const KEY = 'main_title_music';
|
|
|
|
export function playMenuMusic(scene) {
|
|
const existing = scene.sound.get(KEY);
|
|
if (existing && existing.isPlaying) return;
|
|
if (existing) {
|
|
existing.play();
|
|
return;
|
|
}
|
|
scene.sound.add(KEY, { loop: true, volume: 0.5 }).play();
|
|
}
|
|
|
|
export function stopMenuMusic(scene) {
|
|
scene.sound.get(KEY)?.stop();
|
|
}
|