Another question (may be it better suit as Idea for RFE section):
May be it already done, but I cant find this things, in API. The main point that there no need to have field for each key.
Why not to make input like that:
1) when user press key it flag that current key pressed(e.g. in some array)
2) when user release key, it flag that this key released (in same array)
3) when we need some input, we simply check key state in array
Just short example how it works for me:
- when any key pressed it records as AWT event in LinkedList ():
Code:
public void keyPressed(KeyEvent e)
{ eventProcessor.addEvent(e); }
- every game loop I execute all events from that list (calss with game loop should implement eventhandler):
Code:
//method in class with main loop
public boolean handleEvent(AWTEvent e)
{
switch(e.getID())
{
case KeyEvent.KEY_PRESSED:
keyboard.keyState[((KeyEvent)e).getKeyCode()] = true;
- then during game, in update method I can do this:
Code:
//this is in game state class
if (keyboard.keyState[KeyEvent.VK_UP])
makejump();
If someone needed it I can present code and how it works.