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: 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.
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.
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!
You can also check mouse.x against screen coordinates:
// 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.
Thanks, I'm gonna use that! I'll make it global like you said as it seems more versatile to me.