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

Room transitions (help!)

Hi
I was following a tutorial to do room transitions but I realized it only works when the player is facing the implemented direction (written in the Creation Code) of the Object that warps the player to the other Room and I would like that the player warps when facing any direction when it collides with the obj_transition. Here is the video tutorial:

and here is the code:

Obj_transition:
Create Event
/// @desc
targetRoom = -1;
targetX = 0;
targetY = 0;
playerFacingBefore = -1;
playerFacingAfter = -1;

Creation Code of the Obj_Transition in the ROOM:
(targetX and Y are used for the player to appear in a certain location of the room)
targetRoom = rm_forTesting2;
targetX = 240;
targetY = 259;
playerFacingBefore = dir.right; (I think this is the problem. It works when the player collides with obj_transition BUT ONLY if the player is facing "right")
playerFacingAfter = dir.up; (the player will appear in the room facing "up". This can be changed according to where is the entrance of a room)

Also, I am using an Object that is persistent in all the rooms called "gameControl"

Create Event:
guiWidth = display_get_gui_width();
guiHeight = display_get_gui_height();

blackAlpha = 0;

spawnRoom = -1;
spawnX = 0;
spawnY = 0;
spawnPlayerFacing = -1;
doTransition = false;

enum dir
{
right = 0,
up = 90,
left = 180,
down = 270,
}

and its Room Start Event:
/// @desc
if(spawnRoom == -1) exit;
obj_player.x = spawnX;
obj_player.y = spawnY;
obj_player.facing = spawnPlayerFacing;

with(obj_player)
{
switch(facing)
{
case dir.left: y_frame = 7; break;
case dir.right: y_frame = 6; break;
case dir.up: y_frame = 5; break;
case dir.down: y_frame = 4; break;
case -1: x_frame = 0; break;
}
}

And in the Step Event of the obj_player:
var inst = instance_place(x, y, obj_transition);
if (inst != noone and facing == inst.playerFacingBefore)
{
with(gameControl)
{
if(!doTransition)
{
spawnRoom = inst.targetRoom;
spawnX = inst.targetX;
spawnY = inst.targetY;
spawnPlayerFacing = inst.playerFacingAfter;
doTransition = true;
}
}
}


Can someone help me, please?
 
Last edited:
Maybe take a closer look at this line and ask yourself why it's there and what it's doing.
I think it has something to do with the "playerFacingBefore" but I dont exactly know how to change it so my player can face any direction when it is colliding with the obj_transition and go to the other room.
 
Last edited:
Why are you checking playerFacingBefore?
Ok, I tried to make a new variable called "anyDirection" in the Create Event of the gameControl object:

anyDirection = dir.right or dir.up or dir.left or dir.right;

in the Create Event of the obj_transition, I wrote:
anyDirection = -1;

And in the Creation Code of the obj_transition in the Room, I wrote:
playerFacingBefore = anyDirection;

And it works BUT now, it only works when the player stops when moving through the obj_transition (if I keep moving, the transition does not activate). How can I fix that?
 
Top