The idea was making the gameLoop false to pause the game and unpause the game by making the gameLoop true again. It was able to pause and unpause once before the only way to close the game was to use Eclipse's terminate button instead of the x button in the top corner of the game window.
public class Game extends Canvas implements KeyListener{
private boolean isRunning;
public static void main(String[] args){
getInstance().run();
}
// Singleton pattern get instance
public static Game getInstance(){
if (instance == null){
instance = new Game();
}
return instance;
}
private Game(){
isRunning = true;
}
public void run(){
// basic game loop
while(isRunning){
// draws objects here
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
switch (e.getKeyCode())
{
// pause the game
case (KeyEvent.VK_P):
getInstance().setIsRunning(false);
break;
// unpause the game
case (KeyEvent.VK_U):
getInstance().setIsRunning(true);
run();
break;
}
}
}
why are you calling run after you setIsRunning(true)?(now your in a loop inside the input funcion)
if that's not the problem, idk because you barely posted any real code.