I tested it in windows, and the problem was not the same. I had all directions unless the space bar was pressed. I had similar trouble with Choppacide. I would up adding the "F" key as an alternative fire key and that cleared it up. In Choppacide I tried Shift, Cntl, and Alt, and it behaved the same as the Space Bar. There is either a java error with the arrow keys, or with the control keys.
When the space bar is pressed in your game, I have these directions in windows. "N, NE, E, S, W, NW".
I will be back in a little bit.
Here is my key handling code. It seems to work well on most platforms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| public void keyPressed(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_UP) verticle = 1; if(e.getKeyCode() == KeyEvent.VK_DOWN) verticle = -1; if(e.getKeyCode() == KeyEvent.VK_RIGHT) rotation = 1; if(e.getKeyCode() == KeyEvent.VK_LEFT) rotation = -1; if(e.getKeyCode() == KeyEvent.VK_F || e.getKeyCode() == KeyEvent.VK_SPACE) fire = true; if(e.getKeyCode() == KeyEvent.VK_ENTER) button = 1; if(e.getKeyCode() == KeyEvent.VK_ESCAPE) button = 2;
}
public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_UP) if(verticle == 1) verticle = 0; if(e.getKeyCode() == KeyEvent.VK_DOWN) if(verticle == -1) verticle = 0; if(e.getKeyCode() == KeyEvent.VK_RIGHT) if(rotation == 1) rotation = 0; if(e.getKeyCode() == KeyEvent.VK_LEFT) if(rotation == -1) rotation = 0; if(e.getKeyCode() == KeyEvent.VK_F || e.getKeyCode() == KeyEvent.VK_SPACE) fire = false; } |