diff --git a/src/de/teamteamteam/spacescooter/Main.java b/src/de/teamteamteam/spacescooter/Main.java index 22dede0..9dad9eb 100644 --- a/src/de/teamteamteam/spacescooter/Main.java +++ b/src/de/teamteamteam/spacescooter/Main.java @@ -22,23 +22,24 @@ public class Main { public static void main(String[] args) { final GameFrame gf = new GameFrame(); + //Whatever. + new TestEntity(); + new Player(); + //Initialize the GameFrame properly within the AWT EventQueue EventQueue.invokeLater(new Runnable() { public void run() { gf.init(); + gf.drawEntities(); //Draw nothing for the first time. } }); - //Whatever. - new TestEntity(); - new Player(); - //Initialize PaintThread PaintThread pt = new PaintThread(gf); pt.start(); //Initialize EntityUpdateThread EntityUpdateThread ut = new EntityUpdateThread(gf); - ut.start(); + ut.start(); } } diff --git a/src/de/teamteamteam/spacescooter/gui/GameFrame.java b/src/de/teamteamteam/spacescooter/gui/GameFrame.java index bb7e3fd..2a6dbf9 100644 --- a/src/de/teamteamteam/spacescooter/gui/GameFrame.java +++ b/src/de/teamteamteam/spacescooter/gui/GameFrame.java @@ -1,6 +1,7 @@ package de.teamteamteam.spacescooter.gui; import java.awt.Graphics; +import java.awt.Toolkit; import java.awt.image.BufferStrategy; import java.util.Iterator; @@ -44,24 +45,32 @@ public class GameFrame extends JFrame { this.createBufferStrategy(2); Graphics bufferedGraphics = null; BufferStrategy bufferStrategy = this.getBufferStrategy(); - if (bufferStrategy == null) { - System.out.println("Mist"); - } - try { - bufferedGraphics = bufferStrategy.getDrawGraphics(); - //Now we can use bufferedGraphics to actually draw stuff ... - Iterator i = Entity.entities.iterator(); - while (i.hasNext()) { - Entity e = i.next(); - e.paint(bufferedGraphics); - } - } finally { - //We are done, dispose the pen and celebrate the result! - if (bufferedGraphics != null) bufferedGraphics.dispose(); - } + do { //while bufferStrategy.contentsLost() + do { //bufferStrategy.contentsRestored() + try { + bufferedGraphics = bufferStrategy.getDrawGraphics(); + + // Now we can use bufferedGraphics to actually draw stuff + // ... + Iterator i = Entity.entities.iterator(); + while (i.hasNext()) { + Entity e = i.next(); + e.paint(bufferedGraphics); + } + } catch(Exception e) { + System.out.println("Hier geht was schief"); + System.out.println(e); + } finally { + // We are done, dispose the pen and celebrate the result! + if (bufferedGraphics != null) + bufferedGraphics.dispose(); + } + } while (bufferStrategy.contentsRestored()); + bufferStrategy.show(); + } while (bufferStrategy.contentsLost()); + Toolkit.getDefaultToolkit().sync(); - bufferStrategy.show(); } }