I know what you're talking about, I have the same problem. If you find something, can you please tell me?
I'm trying to make a 2-player Pong game. The first player's pad is controlled with W and S, the second player's with the arrow keys. The problem is that for example if you press any other key while you're holding the S key, the pad will just stop wherever it is, until you release and repress the S key. So, that's really annoying. I programmed this using keystrokes and actions (if that's a very bad way of doing this, I apologize, I'm a newb).
Basically I have these lines in the main class's constructor:
1 2 3 4 5 6 7 8
| getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_S, 0), "p1pressedDown"); getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_W, 0), "p1pressedUp"); getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "p2pressedDown"); getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "p2pressedUp"); getActionMap().put("p1pressedDown", p1downAction); getActionMap().put("p1pressedUp", p1upAction); getActionMap().put("p2pressedDown", p2downAction); getActionMap().put("p2pressedUp", p2upAction); |
Then I have 4 inner classes (one for each action), each with a constructor, and an actionPerformed() method that calls the method used for moving the pad.
If someone could help me, that'd be great! Thanks a lot