So I can't use 2 keys at the same time and I'd like that to be able to happen.
My code is here:
if you try and move both of them at the same time, only one will move or none will move. I think it has something to do with this code here:
public KeyBidings(){
Action upAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y2 -=10;
}
};
Action downAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y2 +=10;
}
};
Action wAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y -=10;
}
};
Action sAction = new AbstractAction(){
public void actionPerformed(ActionEvent e) {
y +=10;
}
};
drawPanel.repaint();
InputMap inputMap = drawPanel.getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW);
ActionMap actionMap = drawPanel.getActionMap();
inputMap.put(KeyStroke.getKeyStroke("DOWN"), "downAction");
actionMap.put("downAction", downAction);
inputMap.put(KeyStroke.getKeyStroke("UP"), "upAction");
actionMap.put("upAction", upAction);
inputMap.put(KeyStroke.getKeyStroke("S"), "sAction");
actionMap.put("sAction", sAction);
inputMap.put(KeyStroke.getKeyStroke("W"), "wAction");
actionMap.put("wAction", wAction);