Author Topic: Click on Left/Right Edge to Change Room  (Read 177 times)

Click on Left/Right Edge to Change Room
« on: 29 Jun 2020, 20:51 »
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: Adventure Game Studio
  1. 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.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Click on Left/Right Edge to Change Room
« Reply #1 on: 29 Jun 2020, 20:58 »
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.
There are those who believe that life here began out there...

Re: Click on Left/Right Edge to Change Room
« Reply #2 on: 29 Jun 2020, 22:19 »
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!

Re: Click on Left/Right Edge to Change Room
« Reply #3 on: 29 Jun 2020, 23:54 »
You can also check mouse.x against screen coordinates:

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

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.
« Last Edit: 29 Jun 2020, 23:55 by Khris »
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: Click on Left/Right Edge to Change Room
« Reply #4 on: 30 Jun 2020, 03:08 »
Thanks, I'm gonna use that! I'll make it global like you said as it seems more versatile to me.