Load all project
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
public class GameLoop implements Runnable {
|
||||
|
||||
private final GamePanel panel;
|
||||
private volatile boolean running;
|
||||
|
||||
public GameLoop(GamePanel panel) {
|
||||
this.panel = panel;
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
running = true;
|
||||
Thread thread = new Thread(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long sleepTime = 1000 / GameConfig.FPS;
|
||||
|
||||
while (running) {
|
||||
panel.updateGame();
|
||||
panel.repaint();
|
||||
|
||||
try {
|
||||
Thread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user