Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Egmundo Huevoz on Mon 15/01/2018 16:49:59

Title: [SOLVED] Hotspot GetAtScreenXY in a scrolling room not working properly
Post by: Egmundo Huevoz on Mon 15/01/2018 16:49:59
I'm making a map room, which is pretty big, and therefore scrolling.
I have this line of code, which I use to get what hotspot the character is currently standing, and then do something else with this information.
Code (ags) Select
Hotspot *player_hotspot = Hotspot.GetAtScreenXY(player.x,player.y);
But it doesn't work properly; the hotspots are circles and the game only knows the player is standing in a hotspot in certain areas of this circle, but not in most of it (I know this because I have a label showing me a variable that changes whether or not the player is standing in a hotspot). I know it's the scrolling room's fault because I imported the room code into another room, put a smaller background so the room isn't a scrolling room, and it works perfectly. I've tried with GetViewport, but that only makes matters worse.

Any insight will be greatly appreciated.
Title: Re: Hotspot GetAtScreenXY in a scrolling room not working properly
Post by: dayowlron on Mon 15/01/2018 16:55:00
player's x and y are room coordinates and GetAtScreenXY wants screen coordinates.
You need to adjust the players coordinates within the call.
I believe you need to subtract the ViewPortX and ViewPortY from the coordinates to get the correct screen coordinates.


Hotspot *player_hotspot = Hotspot.GetAtScreenXY(player.x-GetViewportX(),player.y-GetViewportY());
Title: Re: Hotspot GetAtScreenXY in a scrolling room not working properly
Post by: Egmundo Huevoz on Mon 15/01/2018 16:58:57
Incredible... I mean, I've been programming this game for the past 14 hours, but still, I can't believe I missed that (laugh) I was ADDING instead of SUBSTRACTING.

Thanks a lot, now I can go to sleep in peace.