Changing Room Object Compass

T2008

Member
I've recently had to increase the sprite size of my player for melee and shooting weapons. to be 131x132. (it was less than 100). The problem is that when I change rooms, the player's new coordinates are too much into the room. I've posted the code below. The y coordinates now crash because presumably, it's less than sprite height (this was my old code). When I change the x to be room_width less any value under sprite_width, it crashes.

Is there anyway to fix this easily? It's not an option to change the player sprite size. Any help would be greatly appreciated!!!!

Player Intersect Boundary Code:
Code:
{
  if ( x <= 0 )
  {
    x += room_width-(sprite_width); 
    room_goto(obj_compass.west);
  }
  if ( x >= room_width-sprite_width)
  {
    x -= room_width-(sprite_width);
    room_goto(obj_compass.east);
  }
  if ( y <= 0 )
  {
    y += room_height-(sprite_height-50);
    room_goto(obj_compass.north);
  }
Edit:  The above edit isn't working so well now.  This is so frustrating.
  if ( y >= room_height-1)
  {
    y -= room_height-(sprite_height-50);
    room_goto(obj_compass.south);
  }
}
The compass object defines the room directions for the room goto code.

Edit: I've tried (so far with just x coordinates), to adjust the player closer to boundary in Room Start Event. It seems to work but it doesn't seem like it would be the best solution to this issue. Plus, I have some door codes that push the player out at certain spots in the next room (without being part of room transition parent) that would be affected by this code (so I would have to go back and redo those). Any ideas as to a better solution?

Code:
if (!instance_exists(obj_room_transition_parent)) {
    if x > 1780 {
        x = x+80;   
    }
    if x < 120 {
        x = x-80;   
    }
}
 
Last edited:

T2008

Member
The sprite is 131x132, but there is a lot of empty space and player is thin. The extra space is for long sword and gun. When changing rooms, the player will appear far from boundary which looks not the greatest, plus it means nothing can be anywhere near room borders. For some reason I can adjust the y values without problem, only x has to be sprite width.

When I added the below code to the Room Start Event, it looks nicer, and adjusted the Y values in Intersect Boundary Event. I don't know if there are any possible issues with it, but so far it works. So the update code that seems to work fin is below:

INTERSECT BOUNDARY
Code:
{
  if ( x <= 0 ) 
  {
    x += room_width-(sprite_width);   
    room_goto(obj_compass.west);
  }
  if ( x >= room_width-sprite_width)  
  {
    x -= room_width-(sprite_width);  
    room_goto(obj_compass.east);
  }
  if ( y <= 0 )
  {
    y += room_height-(sprite_height-110);  
    room_goto(obj_compass.north);
  }
  if ( y >= room_height)   
  {
    y -= room_height-(sprite_height-70);    
    room_goto(obj_compass.south);
  }
}
ROOM START
Code:
if (!instance_exists(obj_restart_room_transition)) 
&& (!instance_exists(obj_room_transition_parent)) {
    if y > 70 && y < 1000 { //added so if going north/south, x coordinate is not adjusted
        if x > 1780 {
            x = x+60;    
        }
        if x < 120 {
            x = x-60;    
        }
    }
}
 
So im very new to game maker lol, but I do still try to help. I guess all I can say is, pay attention to where the origin of your sprite is ending up when you resize your sprite, it will cause problems.
 
Top