• 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!

GameMaker room to room transition

Night-Ninja

Member
how would I go about making an object that when the player object is touching it and you press E you get taken to another room, thanks in advance
 
H

Homunculus

Guest
You can use something like this in your player object, with the appropriate edits to fit your specific setup:
Code:
if(keyboard_check_pressed(ord("E"))) {
    var _inst = instance_place(x, y, your_roomchange_obj);
    if(_inst != noone) { room_goto(_inst.target_room); }
}
In short, if the letter E is pressed, get the instance of the "room chaning object" that's colliding with your player. If such an instance exists (as in, you are colliding) go to the room that's specified in that object "target_room" variable.
 

Night-Ninja

Member
You can use something like this in your player object, with the appropriate edits to fit your specific setup:
Code:
if(keyboard_check_pressed(ord("E"))) {
    var _inst = instance_place(x, y, your_roomchange_obj);
    if(_inst != noone) { room_goto(_inst.target_room); }
}
In short, if the letter E is pressed, get the instance of the "room chaning object" that's colliding with your player. If such an instance exists (as in, you are colliding) go to the room that's specified in that object "target_room" variable.
where should I put the name of the room I want it to take me to?
 

Night-Ninja

Member
You can use something like this in your player object, with the appropriate edits to fit your specific setup:
Code:
if(keyboard_check_pressed(ord("E"))) {
    var _inst = instance_place(x, y, your_roomchange_obj);
    if(_inst != noone) { room_goto(_inst.target_room); }
}
In short, if the letter E is pressed, get the instance of the "room chaning object" that's colliding with your player. If such an instance exists (as in, you are colliding) go to the room that's specified in that object "target_room" variable.
never mind I figured out where to put it, thank you very much for your help I really appreciate it!
 
H

Homunculus

Guest
Depends, you can just hardcode it inside the room_goto call, but if you have more than one instance of these "room changing objects" throughout the game, the approach above makes a bit more sense.

To further clarify my point, suppose you have a few places around your map that all act as you described above, meaning that when the player is above them and presses "E", there's a room change to a specific room that may be different depending on the instance you are colliding with.
You could have one object for every different room you want the player redirected to, but it makes much more sense to have just one object with a variable telling the player where it is supposed to go. In my code above, that variable is called "target_room".

You'd probably define the target_room as a variable definition, so you just need to drag one of the instances in the room and set that variable to the room you want.
 
Top