4 ms·
So far with game programming the most difficult problem I've had is input states. There doesn't seem to be a clean way to manage it that doesn't get very messy,
by fao_ 6y ago
So far with game programming the most difficult problem I've had is input states. There doesn't seem to be a clean way to manage it that doesn't get very messy, very fast. Even though it should be easy to manage since it's just a state machine!
- simonbw 6y agoBy input states do you mean stuff like knowing whether a key is currently pressed or a mouse button is currently held down? Could you explain what you mean by it gets messy?
- fao_ 6y agoI mean segregating mouse actions. So: Drag, Click, etc. Also handling selection events and so on. I've been using love2d, which basically means you have to set up those manually. Then building a state machine in lua gets very messy. I dunno, maybe I'm just overthinking it
- krapp 6y agoHave you tried SDL2? I don't know what your criteria for "messy" is but its event stack makes it pretty straightforward to get input from the mouse, controller and keyboard.
- softfalcon 6y agoYeah, before you know it, you’re in the land of colliding mouse down events. Best I’ve been able to do is group interaction views together (think inventory and character menus vs the character controller). Separate these view groups so they are triggered by a mode state using an event system that tells each view group which is active. Only update the active view group. This isolates each view group to receive mouse/key events by itself. It also keeps menus that interact with one another consolidated together in one place. This helps you reason out the mouse/key events more easily since you know this view group won’t disrupt the other inactive view groups. Within a view group though, a focused control pattern is a good idea. A simple way is via hit bounding and z-ordering. The top-most, mouse over bounds control is active to receive click events. Everything else is ignoring input. tldr; hierarchy your input controls into groups so you can ignore the input on inactive/not visible ones.