You should not calll repaint(), it ask for a repainting (in the awt thread), and may not do it inmediatelly.
My game loop (using active rendering) always begin from this template:
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
| class Game extends Canvas implements Runnable{ public void run(){ while(true){ doGame(); doRender(); doPaint(); } } public void doGame(){ } public void doRender(){ } public void doPaint(){ getGaphics().drawImage(buffer,....); } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ g.drawImage(buffer,....); } public void start(){ Thread t = new Thread(t); t.start(); } } |
For your problem, you can put some vars to indicate to the rendering stage to draw your dialog over the game.
You can use the same vars to skip the game execution in the doGame() method.
The changes are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| .. public void doGame(){ if(dialog){ } else{ } } public void doRender(){ if(dialog){ } } |
Hope it helps you.
Rafael.-