I'm working in LWJGL and trying to implement pausing when the user presses the 'P' key. Thus far I have this:
boolean gamePaused = false;
while(!Display.isCloseRequested()){
if(Keyboard.isKeyDown(Keyboard.KEY_P) && !gamePaused)
gamePaused = true;
if(Keyboard.isKeyDown(Keyboard.KEY_P) && gamePaused)
gamePaused = false;
if(gamePaused){
while(true){
System.out.println("Game paused.");
if(Keyboard.isKeyDown(Keyboard.KEY_P)){
gamePaused = false;
break;
}
}
}
//...game logic
}
My problem is that it continues playing even when I press the P key.