GMS 2 stop room moving when character dies

Hi everyone
I’m new to GMS 2, and i need some help with something.
I’m creating an infinite runner game, and i want it so that when the player dies, the background stops.
Can i have some help?
 
How are you moving your background?

you can try checking at every step if the player is alive. If yes, move background. If no, do nothing
 
i’m moving the background just by setting the horizontal speed of the room to -0.4.
and how do i do that?
do you have any example code?
(sorry i’m new to game maker studio 2 so i don’t know the language very well)
 

Slyddar

Member
The horizontal speed you are setting can be controlled with code, which is what you need to do if the game is running. You can run this code when the player dies to stop the background, and run it again with a -0.4 value when you want to start the movement.
Code:
//get layer id
var lay_id = layer_get_id("Background");

//set layer speed to 0
layer_hspeed(lay_id, 0)
 

Rexzqy

Member
i’m moving the background just by setting the horizontal speed of the room to -0.4.
and how do i do that?
do you have any example code?
(sorry i’m new to game maker studio 2 so i don’t know the language very well)
So basically check
if instance_exists(obj_player or whatever ur object for player is)
{
your code for moving background
}
 

ophelius

Member
There's a lot of background functions you can use to control it, including v and h speeds. It's all in the manual
 
The horizontal speed you are setting can be controlled with code, which is what you need to do if the game is running. You can run this code when the player dies to stop the background, and run it again with a -0.4 value when you want to start the movement.
Code:
//get layer id
var lay_id = layer_get_id("Background");

//set layer speed to 0
layer_hspeed(lay_id, 0)
i did that but that just stops the background completely.
what’s the code to set the background hspeed?
 

FrostyCat

Member
i did that but that just stops the background completely.
what’s the code to set the background hspeed?
That IS the code for setting the background's horizontal speed. If you want it to move instead of stopping, change the 0 to the -0.4 you started with.
GML:
var lay_id = layer_get_id("Background");
layer_hspeed(lay_id, -0.4);
The next time you see an unfamiliar function on a forum post or tutorial, use the Index tab on the Manual to learn what it does. That will let you easily find articles like this.
 
Top