Game Maker: Studio Sound wont play when moving to next room?

841 views Asked by At

Im making a small game in Game Maker Studio. I have a piece of code that moves the player to the next room when he touches obj_star: this works. I have another line that tries to play sound_collect when the star is touched, but the game just moves to the next room without playing the sound. My code is as follows:

//Get the player's input
key_right = keyboard_check(vk_right);
key_left = -keyboard_check(vk_left);
key_jump = keyboard_check_pressed(vk_space);

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,obj_wall))
{
vsp = key_jump * -jumpspeed
}
//Horizontal Collision
if (place_meeting(x+hsp,y,obj_wall))
{
while(!place_meeting(x+sign(hsp),y,obj_wall))
{
    x += sign(hsp);
}
hsp = 0;
}
x += hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,obj_wall))
{
while(!place_meeting(x,y+sign(vsp),obj_wall))
{
    y += sign(vsp);
}
vsp = 0;
}
y += vsp;

//Sounds
if (place_meeting(x+hsp,y,obj_star))
{
sound_play(sound_collect)
};
3

There are 3 answers

0
Dmi7ry On BEST ANSWER

At first, you need to use the new audio engine and functions audio_.... All functions sound_... is legacy and don't work with the new audio engine.

enter image description here

At second, I not sure that

if (place_meeting(x+hsp,y,obj_star))
{
    // play
}

is a right way. For example, if you destroy obj_star after touching then you can play the sound in the Destroy event of the obj_star.

0
Exel Gamboa On

Just in case, check for any audio_sound_gain() you used in another part of the code. It seems that when you fade in a sound effect or music, it stays faded or muted until you fade it out to unmute. I am thinking that the fade is applied directly to the sound asset you are using.

0
Calvin On

What I do for may games is add a main menu. When the player clicks a menu option the desired music plays. Then when a new room is loaded that needs different music you can use audio_stop_all(); and then play any sound you want with audio_play_sound("sound_Song, 10, false); Hope this helps!