Hi there,
I’m working on my first Java game at the moment (which is a sidescroller like R-Type) and I have a little problem:
I added a KeyAdapter to my JFrame in order to move the spaceship on the screen.
Actually that works fine but with this approach I can only do one thing at the same time. So I can only move the ship OR shoot but i can’t move the ship AND shoot at the same time.
I thought about parallelizing the input with threads somehow but I really have no clue how to do this.
Any ideas?
Cheers
Wolfner
P.S.:
This is how my KeyAdapter looks at the moment:
private KeyAdapter keyAdapter1 = new KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
model.playerPositionChanged(1);
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
model.playerPositionChanged(2);
}else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
model.playerPositionChanged(3);
}else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
model.playerPositionChanged(4);
}else if(e.getKeyCode() == KeyEvent.VK_SPACE){
model.shot();
}
};
public void keyReleased(java.awt.event.KeyEvent e) {
model.playerPositionChanged(0);
}
};