Continuing music into the next scene

Is it possible to add a sound file that plays continuously, even when you switch scenes? As of now, I can only make the song start from the beginning of each new scene.

Hi @Mark_Davis!

currently there’s no continuous music between scenes possible without coding it.

Below you can find a code snippet you can copy into every scene to make your music pick up where it left off. Make sure to upload your music to the Upload -> Audio upload - tab and replace the audio ID from the example with your own. If you are using stage sounds, remove them to avoid playing back the sound twice.

//Replace the soundId with your own music!
let soundId = "6O3KD00ze0AwTCveq7k0guZFVabtZ5iiV7jMthEFwAW";

Scene.loadSound(soundId, function (sound) {
    playMusic(sound);
});

function playMusic(music : Sound) {
    let currentPosition = Space.getProperty("trackPosition") || '0';
    
    music.play(true);
    music.setCurrentPosition(parseFloat(currentPosition));

    Scene.onExit(function() {
        Space.setProperty("trackPosition", music.currentPosition().toString());
    });
}

Here’s the example in action: https://cospac.es/edu/4CmI

Hi Mark–it’s been two years, but could you possibly allow me to remix your game you shared? I am very confused as to what the text in red means, and I’m trying to help a 3rd grader!

Kelly,

   I don't know if you received my message, but again, I don't actually have an available project to share with you.  It was a student's project from 2 years ago that is no longer in my database.  However, you should be able to add the code above as suggested by Stefan.

   Hope this helps,
                   Mark

Thanks Mark! I’ll check it out!