I'm making a game where each level has its own scene. When a level is completed it switches to the next scene and restarts the music that's playing. How do I make it so that the music plays continuously between scenes?
- Add a
managerscene, where stuff should happen independently from other scenes. You can set and remove scenes, but the
managershould be kept as it is.
- On the
managerscene, add an object that receives messages, and each message sets a property named
songto a integer number. You know, if a message sensor looking for
song_1message is activated, sets the property
1, and so on.
- On the same object, make a logic to play each song (on loop stop mode) according to its property number. You know, if property
song_1.ogg, and so on.
- On each level, make an object send a message at startup to change the song. For example,
Messagewith the subject
song_1, and so on according to the level.
If everything went well, when a level restarts and the song is already playing, it shouldn't restart the song, and when the property
song changes the object will stop the previous song and start the new one according to the logic.
Using this method of a
manager scene also helps to keep everything on only one place, instead of looking for each scene to change the song or whatever.