Input handling for overlay UI

Jun 7, 2012 at 10:13 PM

I'm trying to overlay UI elements on top of my game. How can I tell when a UI component (other than the desktop) is clicked so I can ignore the input event in the game logic?

Coordinator
Jun 8, 2012 at 8:06 AM

Check the properties "IsInputCaptured" and "IsMouseOverGui" of the Screen class.

There's a big block of documentation above each of those methods, but normally you'd do something like this:

- By default, you use IsMouseOverGui to decide if your game of the GUI should handle mouse move events

- If a mouse button is pressed down while the mouse was in the game area, do not send any input to the GUI. All input belongs to the game, even if the mouse goes over the GUI, until all mouse buttons have been released again.

- If a mouse button is pressed down while the mouse was over the GUI, it sets IsInputCaptured to true and all input belongs to the GUI, even if the mouse goes over the game, until all mouse buttons have been released again

That way, the player can for example draw a selection rectangle around some units and there won't be weird things happening when he crosses a GUI control.