Working on a very simple mobile game and I have just started looking into game audio in Phaser 3 for the first time. Mostly things are making sense following the labs examples and a few forum post examples too. Currently though I am struggling with how to stop audio from triggering multiple times when a scene is left and restarted.
I have a background track that I want to play from the start screen across all scenes of my game without stopping. I trigger the audio playing on my start screen but after going through a few menus and coming back to the start screen the audio plays again over the top.
After preloading the audio and adding the below code to the create function of my start menu scene, the audio replays itself multiple times if the start menu is left and revisited:
let sound = this.sound.add('background');
sound.stop();
sound.play();
I understand that it is probably because I am not stopping the existing audio, so a new instance of it is created and starts playing. I’m just wondering if someone could point me to an example or provide a small snippet detailing how I might be able to stop the old instance of it. I looked at a number of examples and googled a few search terms but couldn’t really find anything that applies to this particular use case.
Thanks