I’m currently trying to solve a UI issue with Space Snake Galaxies. On the universe map you can bring up highscore and level info for each galaxy where you play.


When you click outside of either they dissappear.
The issue is that there are places where you can both click outside of the highscores and on a button and so both detect that a mouse click has occurred. Why can you do this? Because I’m still using the old basic way of handling controls through simple function primitives. i.e. isMouseDown, isKeyDown, getMouseX and getMouseY. i.e.
if ( getControls().isMouseDown(Controls.LEFT_MOUSE) ) {
// do something
}
It’s crazy that indie game programmers still recommend doing this. It’s like the GOTO of controls. Dead simple and you can build anything with it, but it’s a real mess to code anything sophisticated (like good buttons!).
In GUIs you don’t do this. When I press a key an event is dispatched to the top level component. If it cannot handle the event it will pass it on to another component (and so on and so forth). This means the GUI is passive; it’s mouse and keybaord handling code is only run when an event occurres. With the basic active code above it will make a check on every frame to see if the mouse is down or not, wasting CPU time.
But there is another difference. If an event can be handled by a component then the event is removed. That sole property is almost impossible to build using basic functions like isMouseDown. You either need to permanently alter the state of the controls (so future checks on isMouseDown return false) or tie all components together globally (have a button check if any other buttons have handled mouse controls first, and if they haven’t then it will).
I think the solution will be to build a passive event system into my framework. To allow easy event based input for buttons and panels whilst keeping direct input for guns and shooting. Because sometimes all you need is isMouseDown.


