1
public void buttons(){
int c = WHEN_IN_FOCUSED_WINDOW;
Action right = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
player.setVX(2);
}
};
Action stop = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
player.setVX(0);
player.setVY(0);
}
};
Action up = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
player.setVY(-2);
}
};
getInputMap(c).put(KeyStroke.getKeyStroke("D"), "pressed");
getActionMap().put("pressed", right);
getInputMap(c).put(KeyStroke.getKeyStroke("released D"), "released");
getActionMap().put("released", stop);
getInputMap(c).put(KeyStroke.getKeyStroke("W"), "pressed");
getActionMap().put("pressed", up);
getInputMap(c).put(KeyStroke.getKeyStroke("released W"), "released");
getActionMap().put("released", stop);
}
這是爲什麼,當我按W或D它上升...這個鍵綁定有什麼問題?
問題是什麼?
d應該向右走
你確定它的鍵綁定,而不是'setVX'方法?爲每個'actionPerformed'方法添加一個調試語句,以查看按下'D'是否實際上調用'setVX'(通過'actionPerformed'方法) – MadProgrammer 2013-02-27 03:50:41
是的,我的setVX是正確的,但是當我擺脫我的setVY動作執行 – user2113792 2013-02-27 04:01:16
我的VX的工作..我不知道爲什麼它工作時,我擺脫我的VY ation執行 – user2113792 2013-02-27 04:01:57