Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. // Thread Variable
  2. private Thread gameThread;
  3.  
  4. public synchronized void start() {
  5.     if (running) {
  6.         return;
  7.     }
  8.     running = true;
  9.     gameThread = new Thread(this);
  10.     gameThread.start();
  11. }
  12.  
  13. public synchronized void stop() {
  14.     if (!running) {
  15.         return;
  16.     }
  17.     running = false;
  18.     try {
  19.         gameThread.join();
  20.     } catch (InterruptedException e) {
  21.         e.printStackTrace();
  22.     }
  23. }
  24.  
  25. // Der eigentliche Game Loop
  26. // Die Klasse implementiert Runnable
  27. public void run() {
  28.     this.requestFocus();
  29.     init();
  30.     long lastTime = System.nanoTime();
  31.     double amountOfTicks = 60.0;
  32.     double ns = 1000000000 / amountOfTicks;
  33.     double delta = 0;
  34.     long timer = System.currentTimeMillis();
  35.     while (running) {
  36.         long now = System.nanoTime();
  37.         delta += (now - lastTime) / ns;
  38.         lastTime = now;
  39.         while (delta >= 1) {
  40.             tick();
  41.             delta--;
  42.         }
  43.         render();
  44.         if (System.currentTimeMillis() - timer > 1000) {
  45.             timer += 1000;     
  46.         }
  47.     }
  48. }
  49.  
  50. // Alles Render Zeugs
  51. private void render() {
  52. }
  53.  
  54. // Alle Updates
  55. private void tick() {
  56. }
  57.  
  58. // Main Methode
  59. public static void main(String[] args) {
  60.     new Game().start();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement