Adventure Game Studio | Forums

AGS Support => Beginners' Technical Questions => Topic started by: hocuspocus on Mon 29/06/2020 20:51:28

Title: Click on Left/Right Edge to Change Room
Post by: hocuspocus on Mon 29/06/2020 20:51:28
I'm trying to make a first-person point-and-click game, where the player has to click on an edge in the room to go to other rooms; the cursor's graphic would also change when hovering over that edge to show the direction (ie if hovering on left edge, show the left-arrow cursor sprite). How do I code this in my game? Here's what I tried:
Code (ags) Select
function Room.LeftEdge_AnyClick(){player.ChangeRoom(2);} but it says that Room is already defined. I know I can make hotspots on the room edges for the player to click on but I was wondering if there was another way.
Title: Re: Click on Left/Right Edge to Change Room
Post by: Cassiebsg on Mon 29/06/2020 20:58:49
You can't click on Edges, they are used to walk past.
You need to create a hotspot for each "clickable edge" you want instead.
Title: Re: Click on Left/Right Edge to Change Room
Post by: hocuspocus on Mon 29/06/2020 22:19:10
Ah, I figured. I was just afraid that I will end up with too many hotspots to keep track of, but since I don't have another option I will just use them. Thanks!
Title: Re: Click on Left/Right Edge to Change Room
Post by: Khris on Mon 29/06/2020 23:54:08
You can also check mouse.x against screen coordinates:

Code (ags) Select
// add to room script
function on_mouse_click(MouseButton button) {
  if (button != eMouseLeft) return; // do nothing
  if (mouse.x < 30) player.ChangeRoom(2);  // leftmost 30 pixels
  if (mouse.x > 290) player.ChangeRoom(3);  // assuming a viewport width of 320
}


It's also possible to do this globally, for instance by adding custom properties to your rooms that store the neighboring rooms.
And you can use the global repeatedly_execute to change the mouse cursor when the mouse is over a room edge.
Title: Re: Click on Left/Right Edge to Change Room
Post by: hocuspocus on Tue 30/06/2020 03:08:34
Thanks, I'm gonna use that! I'll make it global like you said as it seems more versatile to me.