How to check for UI mouse events properly

Started by
2 comments, last by web383 11 years, 8 months ago
Hello!

When developing my game, I ran into a problem: How can I properly check the mouse event for my UI? For example if I want to click on the map, then I dont want the game to handle that click, just only the UIHandler. Or closing a window, and in the game the left click is shooting, or casting a spell. Then if I want to close the window, my character shoots a fireball and closes the window. How can I solve this problem?
Advertisement
Send your mouse event to the UI first and make the UI return a true/false value if it handled the event or not. If not, send the event to the game code.
Really good idea. I'll look into it :) Thanks for help
In the past, I've written game logic to include several screens. You can think of each screen as a layer of updates with the bottom layer being the game level/logic. Input is filtered from the top screen down to the bottom. On input, the screen can choose to handle it accordingly, and/or pass the input along to the one underneath it.

This makes it easy to pop up a 'pause screen' and halt updates to the 'game screen'. Or in your case, create a 'UI screen' and if input was handled, don't pass it down to the 'game screen' - just like Faelenor suggested.

This topic is closed to new replies.

Advertisement