• 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 Transitions: Multiple Start Locations/Destinations

I'm gonna set up the question here:

Say you have a "top down" game with a total of 5 rooms each sized at 4000x4000 (arbitrary size)...
Imagine looking down on some grand map, seeing that the rooms are situated like the following:
Room#1 is in the center, and rooms #2, #3, #4, #5 are next to each of the 4 sides of room#1 (#2 is North, #3 is East, #4 is South, and #5 is West)...
Let's say the player character is at "x 30 y 5" in room#1 and I want him to transition to room#2 with the same x coordinate, but have the appropriate y coordinate for wherever would be the "bottom of room#2..."
Question: Is there a simple way to program this... I want to travel from the top of a room to the bottom of the next, and I want to travel from the far left side of a room to the far right side of the room "West" of that room, and so on.
My sense is that there would most likely be a total of 8 scripts/ pieces of programming?
How hard is this? It's gotta be common, I would think... Keep in mind that I would want the player to land precisely in the location of the destination room in alignment with the location of the starting room...
BTW, I'm not asking for code; I just want to know that this is doable, instead of making a ton of warp objects lining the parameters of every room. thx, and I really appreciate the help and responses I've received over the past few years...
 

samspade

Member
There are a number of different ways. Generally, what you want to do is one type of transition object. Then have a means of triggering that transition object. Then decide on a way to set specific instance variables for that object. There are several ways to do this. If you're creating things in the room editor, I would recommend object variables. Otherwise use the creation code. Now when an object triggers the transition you can have specific variables for the next room which can include, location, facing, everything.

Since only persistent items will persist through a room change you next need to determine the method you are going to use to pass variables from room to room. You could use globals, but I prefer to create a persistent transition object.

For example:

Code:
//transition space
if (triggered) {
    var new_transition_object = instance_create(x, y, layer, obj_transition_handler);
    with (new_transition_object) {
        ///set all values here - e.g.
        player_x = other.player_x;
        player_y = other.player_y;
    }
    room_goto(my_room);
}

///obj_transition_handler
///room start event

instance_create_layer(player_x, player_y, layer, obj_player);
instance_destroy();
Note that there is a lot of code missing in the above that would have to be supplied or changed by you depending upon what systems you are using.

This video is a great explanation of how to do it that is very similar and much more indepth:

 

TheouAegis

Member
Or how about a transition_type variable set to 0 for off, 1 for up, 2 for right, 3 for down, 4 for left. In the Room Start event, or one of the Step Events if your rooms are persistent:
Code:
switch transition_type {
case 0: break;
case 1: y = room_height; break;
case 2: x = 0; break;
case 3: y = 0; break;
case 4: x = room_width; break;
}
Of course there's more code involved with that, but whatever. If the player is persistent and that code is in the player object, that's about all you'd need.

HOWEVER, I do have issue with your room layout. It's too arbitrary to be easily workable. Map everything out on a grid using (0) for the top-left cell and counting left-to-right. This allows you to let the game calculate what room to go to next based on the direction the player exits so that technically you wouldn't even need any extra objects for the transitions.
Code:
if transition_type != 0 {
   switch transition_type {
    case 1: y = room_height; mapID -= map_width; break;
    case 2: x = 0; mapID++; break;
    case 3: y = 0; mapID += map_width; break;
    case 4: x = room_width; mapID--; break;
   }
   room_goto(mapID)  //or room_goto(roomMap[mapID]) if you stored the room layout in an array
}
 
Top