ZombieEscape: Multiple KeyBinding at one moment?
Hi Guys! Unome again. The JavaApplet I've been working on is becoming a killer success. My character now has an environment it can explore. He can jump, run, crouch, heal, commit suicide, pause, restart.... and a variety of other things... My main problem at the moment is this:
I cannot perform multiple actions at once:
Situation: Player is pressing the forward key, and then strikes jump(still holding forward key)
RESULT: In normal games you would jump forward... When I strike the jump action the forward action is canceled and he jumps straight up.
HOWEVER: If I strike the keys at the exact same time (kinda hard) he jumps forward.
Same priuncipal apply's when firing gun, jumping, crouching, healing ect...
Heres my action code:
Code:
......................
....................
private void bindKeys() //sets up key actions for the program
{
JRootPane rp = getRootPane();
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
InputMap inputMap = rp.getInputMap(c);
ActionMap actionMap = rp.getActionMap();
inputMap.put(KeyStroke.getKeyStroke("LEFT"), "LEFT"); //creates left action
actionMap.put("LEFT", walkleft);
inputMap.put(KeyStroke.getKeyStroke("RIGHT"), "RIGHT"); //creates right action
actionMap.put("RIGHT", walkright);
inputMap.put(KeyStroke.getKeyStroke("SPACE"), "SPACE"); //creates space action
actionMap.put("SPACE", fireball);
inputMap.put(KeyStroke.getKeyStroke("P"), "P"); //creates space action
actionMap.put("P", pause);
.............................
.............................
............................
private AbstractAction walkleft = new AbstractAction() { //action that moves the ball left
public void actionPerformed(ActionEvent e) {
Moveball.moveleft();
}
};
private AbstractAction walkright = new AbstractAction() { //action that moves the ball right
public void actionPerformed(ActionEvent e) {
Moveball.moveright();
}
};
..................
..................
I think the trick lies in the "WHEN_IN_FOCUSED_WINDOW" I'm not quite sure though.
Mmk Java Jenius's. Can you solve this error?