Hi all,
Looking for a bit of advice here on the best way of how to handle input in my game engine. I don’t have any code to show you (well, none that works completely) but I do have several ideas - but really they seem to suck/make it difficult for the end developer who is creating the game.
Idea 1.
Have some class that extends KeyListener and has 3 variables that store the keycode for each key pressed, released etc. Then, an update method in my engine class will somewhere call the method getKeyPressedKeyCode() for example on that class, and then have a switch statement to decide what to do (i.e. if left key pressed, decrease x by 5.0 on some sprite).
However, could there be any chance of being multiple key presses in one gameloop, or could input be missed?
Idea 2.
Have another class, possibly something like EventQueue that collects all the events from a key being pressed and released etc. When this happens, in another class (Keyboard) I would have a collection of all the keycodes/keyevents and depending on which was pressed, from the EventQueue it would set them to true/false.
Then, in the update method in the game engine, there would be again checks to decide what to do based on what keys are pressed.
Does anyone have any better ideas?
My main problem is, as this is a game engine and not just a game, I’m trying to make it kind of simple of the developer. Therefore I cannot set a variable in say the SpriteManager to say (moveLeft == true) because one developer may want the left arrow key to be something else, or not move left at all etc. Therefore I’m trying to be as generic as possible (which is difficult!)
So any suggestions, ideas would be gratefully received and should get me moving on with the rest of my engine!
Thanks!
Just a FYI: I’m using Java2D for displaying graphics on the screen, not something like LWJGL. I wish I had of done now, particularly as there seems to be classes there to handle input etc, but with 6 weeks left on this, I don’t think there is time to change now!