How do you handle input?
Posted: Sat Oct 25, 2014 9:34 pm
Just wondering how other people set up the input handling for their game. I've run into an interesting situation while trying to implement UI buttons with certain requirements:
1) Buttons are highlighted when moused-over.
2) Clicking a button depresses it, but does not trigger an on_click() event to be called.
3) Releasing a click while on a button that you currently have depressed, triggers an on_click() event to be called.
I had to get a little creative to avoid the following problems:
4) Mousing-over a button while you have another button depressed does not highlight the second button.
5) Releasing a click while off a button that you currently have depressed, does not trigger an on_click() event.
My original solution was very hacky, but I basically made some tables to check for mouse_pressed events and mouse_released events and updated them using Love's built-in callback functions. I then did a lot of testing for hovering and such in my GameObjects.
As a cleaner solution, I'm considering building some kind of InputManager class and just moving as much as I can into there, but I wanted to know what other people did before I started doing that. I realized I couldn't continue cleanly in the way I was writing it because I eventually will need to distinguish between GameObjects that are in front of other GameObjects and having the nearest one take priority. It seems to be the best way to do this is to, as before, use Love's built-in callback functions to update an InputManager, and then somehow pass that information along to my Game class and have the Game class say, "Hey, GameObject #366, you were clicked." In this situation, I would make the InputManager global.
Any insight appreciated.
Thank you.
<3
1) Buttons are highlighted when moused-over.
2) Clicking a button depresses it, but does not trigger an on_click() event to be called.
3) Releasing a click while on a button that you currently have depressed, triggers an on_click() event to be called.
I had to get a little creative to avoid the following problems:
4) Mousing-over a button while you have another button depressed does not highlight the second button.
5) Releasing a click while off a button that you currently have depressed, does not trigger an on_click() event.
My original solution was very hacky, but I basically made some tables to check for mouse_pressed events and mouse_released events and updated them using Love's built-in callback functions. I then did a lot of testing for hovering and such in my GameObjects.
As a cleaner solution, I'm considering building some kind of InputManager class and just moving as much as I can into there, but I wanted to know what other people did before I started doing that. I realized I couldn't continue cleanly in the way I was writing it because I eventually will need to distinguish between GameObjects that are in front of other GameObjects and having the nearest one take priority. It seems to be the best way to do this is to, as before, use Love's built-in callback functions to update an InputManager, and then somehow pass that information along to my Game class and have the Game class say, "Hey, GameObject #366, you were clicked." In this situation, I would make the InputManager global.
Any insight appreciated.
Thank you.
<3