I am making a recreation of Space Invaders inEstoy recreando el SpaceInvaders en Java and I want to create ay quiero hacer un delay between the missiles of my spaceshipentre misil y misil.
@Override
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
// TODO Auto-generated method stub
if (key == KeyEvent.VK_LEFT&&n.boom==0) {
left=true;
}
if (key == KeyEvent.VK_RIGHT&&n.boom==0) {
right=true;
}
if (key == KeyEvent.VK_SPACE&&n.boom==0) {
space=true;
}
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
int key = e.getKeyCode();
// TODO Auto-generated method stub
if (key == KeyEvent.VK_LEFT) {
left=false;
}
if (key == KeyEvent.VK_RIGHT) {
right=false;
}
if (key == KeyEvent.VK_SPACE) {
space=false;
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
In my code,En mi codigo la variable space is a booleanes una variable that when it'sbooleana que cuando es true then it creates a new "missile" in another functioncrea un nuevo objeto misil en otra función. All the code works in aEl código funciona en un while(true) loop that makes everything move. The problem is that if I use some kind ofpor lo que si hago un thread.sleep it will stop all the game() se va a parar todo el juego.