I'm 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.
This code is in the Step event
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)
};
//Next Level
if (place_meeting(x+hsp,y,obj_star))
{
room_goto_next()
};