• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Not possible to change music between Rooms?

R

Rocore

Guest
Hello,

I'm having a lot of problems trying to make change the background music from one room to another.
I wanted to put a track as an intro at the starting screen (Room0) and then change it when the user clicks the start button and enters to Room1.

Tried everything but not working,the starting intro music at Room0 will never stop.
Tried different ways, if - else if... then even if - else, but nothing works.

Both tracks are in the same music group.

In the object, at create sheet I have this:
GML:
if (!audio_group_is_loaded(background_music)){
    audio_group_load(background_music);   
}
And at the Async save/load I have this:
GML:
if (room == Room0){
    audio_play_sound(intro_music, 0, true);
}

if (room == Room1){
    if audio_is_playing(intro_music){
        audio_stop_sound(intro_music);
    }
audio_play_sound(playing_music, 0, true);
}
Not working.

Even with this, it will not work:
GML:
if (room == Room0){
    audio_play_sound(intro_music, 0, true);
    
}else if (room == Room1){

    if audio_is_playing(intro_music){
        audio_stop_sound(intro_music);
        
    }
    
audio_play_sound(playing_music, 0, true);
}
I have even tried directly to do this:
GML:
if (room == Room1){
audio_play_sound(playing_music, 0, true);
}
But it won't start at Room1 anyways.

Any idea?

Thank you a lot in advance :)
 

Nidoking

Member
Is all of that in the Async Save/Load event? Because that only happens once, when you asynchronously load the audio group. If you want something to happen at a later time when the music is already loaded, you'll need to use an event that happens at that time.
 
R

Rocore

Guest
Is all of that in the Async Save/Load event? Because that only happens once, when you asynchronously load the audio group. If you want something to happen at a later time when the music is already loaded, you'll need to use an event that happens at that time.
All is inside the AsyncSave/Load at the object, the object is dropped at Room0 (starting screen).
 

kburkhart84

Firehammer Games
I'm actually making a sound asset that handles the details, but it isn't done yet. It will be a paid asset that handles a lot more than just this. It's easy enough to do it on your own though.

1. Forget the Async stuff. You don't need it just to control when your music loads, changes, etc...
2. Make a global variable that stores the music that is currently playing. It doesn't store the name of the song resource, rather the index as returned by the audio_play_sound() function.
3. In the same code that changes rooms(or in some object like a controller in the new room, or wherever else makes sense, that runs once in the beginning of the room), you first stop the sound that is playing(using the global index you stored). Then, you play the new music, storing that index in the global variable.

As long as you store the currently playing music index in the variable, then any time you play new music, just stop the previous music. A convenient way to do it would be to make a function out of it.
 
R

Rocore

Guest
I'm actually making a sound asset that handles the details, but it isn't done yet. It will be a paid asset that handles a lot more than just this. It's easy enough to do it on your own though.

1. Forget the Async stuff. You don't need it just to control when your music loads, changes, etc...
2. Make a global variable that stores the music that is currently playing. It doesn't store the name of the song resource, rather the index as returned by the audio_play_sound() function.
3. In the same code that changes rooms(or in some object like a controller in the new room, or wherever else makes sense, that runs once in the beginning of the room), you first stop the sound that is playing(using the global index you stored). Then, you play the new music, storing that index in the global variable.

As long as you store the currently playing music index in the variable, then any time you play new music, just stop the previous music. A convenient way to do it would be to make a function out of it.
Solved it!

Thank you :D
 
Top