Jump to content


Photo

~SOLVED~ Room Changing Glitch


  • Please log in to reply
3 replies to this topic

#1 ScaryPotato

ScaryPotato

    GMC Member

  • GMC Member
  • 231 posts
  • Version:Unknown

Posted 13 August 2012 - 03:08 AM

In my game, there are tons of rooms, but it seems like two of them have a mind of their own.
What appears to be happening when the player goes to switch rooms is rather than going to the new room location called up in code, the player appears in the new room with the values for the location of the warp object in the previous room!

So, if the warp_object in room A is located at x=150 and y=120, but the creation code in the warp is x=200 and y=250, the player will go to room B, but at location x=150 and y=120. I have tried erasing the warp object and re-doing the code, and even made a copy of one room to replace the original, but it still happens. If anyone has had this happen to them, or know what might be the cause of it, I'd like to know, because this is the only thing keeping my game from being finished off! Thanks in advance:)

Here's the code I use to change rooms:

Player Collision Event with the Warp Object:
if other.WarpActive=1//This is activated when you beat a boss
{
sound_play(WarpSound);
cc = instance_place(x,y,WarpAccessorObj);
if (cc != noone) 
{
room_goto(cc.Level);
MitchObj.x = cc.X;//Player Object
MitchObj.y = cc.Y;

with MitchCameraObj//Just an object to move with player at a slight delay
{
MitchCameraObj.x = MitchObj.x;
MitchCameraObj.y = MitchObj.y;
}

instance_create(x,y,MitchCreateFaderObj);//Object to obscure everything during room transitions.
}
}
else
{exit;}

Creation Code for WarpAccessorObj:
Level = LvlB1
X = 156
Y = 60

Here are a couple screenshots to show what I mean:

Leaving this room (I was trying out different values to see if there was any change. The bottom values are the ones I want):
Posted Image

Going to this room:
Posted Image

Edited by ScaryPotato, 14 August 2012 - 02:15 AM.

  • 0

#2 youngjake

youngjake

    GMC Member

  • GMC Member
  • 87 posts

Posted 13 August 2012 - 07:04 AM

Just put player.x=whatever, player.y=whatever wherever you decide to change rooms...?
  • 0

#3 torigara

torigara

    GMC Member

  • GMC Member
  • 6483 posts

Posted 13 August 2012 - 09:11 AM

Room_goto doesn't immediately take the place at the moment you call it but will defer to the end of code. That is explained right below the description of room_goto (at least in GM6-GM8.1):

When calling one of the above functions to change the room or end or restart the game, please realize that this change does actually not occur at that precise moment. It only happens after the current action is fully executed. ...

Even if you set x and y right after room_goto(), it still takes place in the current room. When Game Maker actually moves to the new room, your object will be re-created at the initial place. You probably have to change its position after the it actually goes to the next room in the Room Start event.
// When you move the room
global.nextx = cc.x;
global.nexty = cc.y;
room_goto(cc.Level);
// Room Start event of some object
MitchObj.x = global.nextx;
MitchObj.y = global.nexty;

  • 0

#4 ScaryPotato

ScaryPotato

    GMC Member

  • GMC Member
  • 231 posts
  • Version:Unknown

Posted 14 August 2012 - 02:14 AM

torigara, I played around with your idea for a little bit, but things kept getting stranger and stranger with each attempt. Finally realizing that there was only one option left, and it was to move the chunk of code into my player's Step Event (rather than Collision Event with the object). With that simple change, the original code works properly!

Thanks to both you guys for taking a crack at helping out though :)
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users