Hello,
In one of my escape rooms I have implemented an audio system that plays background audio based on the scene you are in.
For this I use the JS library called "Howler.JS". It's very small and easy to use.
Look in the source, just at the <body> tag. Under the <body> tag I added;
Under <div id="pano"></div> I added:
| <script> |
| var myCurrentScene = ""; |
| function setMusic() { |
| audioManager.update(myCurrentScene); |
| } |
| </script> |
I place three audio files in a sounds directory called: wind.mp3, inside.mp3, piano.mp3
In the audio-manager I defined the sounds I want to hear per scene, as well as the volume.
Now every time you switch scene if fades out / in into the new music. It only switched the music if the target scene has another music set.
Hope this script helps!
greetings,
Joost