I’m working on a game with 3 separate scenes Menu, Tutorial and Game (and I may add more later). So the general structure of the project is like so:
- PreloaderScene
- MainMenuScene
- TutorialScene
- GameScene
Each scene has buttons to navigate menus and to change between scenes. When pressed these buttons should play the same sound effect in each scene. Also, in the main menu there is a Sound ON/OFF
option. When the player has selected OFF it shouldn’t play the sounds in any scene.
At the moment, I’m loading all the needed sound effects per scene, like so:
// in game scene .create()
this._button_start = this.sound.add('gui_forward');
this._button_back = this.sound.add('gui_back');
this._explosion = this.sound.add('explosion');
// etc
It’s similar for the MainMenu and Tutorial scenes, but doesn’t this load the same audio multiple times? Also when a sound should be played (button, powerup, explosion etc.) I need to check the Sound=OFF option in each scene.
I’ve already got a global Settings object that is global/shared so it’s used by all scenes. So now I’m thinking it might be better to also create a global/shared sound object that handles all the playing of sound effecs, so then I can load the audio and check the Sound=OFF setting in just one place.
I guess my question is:
- What are the best practices for Phaser3 and loading/playing sound effects with separate scenes?