interference2u
Member
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?
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: