Advertisement
TermSpar

Game Loop

May 25th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1.         this.requestFocus();
  2.         long lastTime = System.nanoTime();
  3.         double amountOfTicks = 60.0;
  4.         double ns = 1000000000 / amountOfTicks;
  5.         double delta = 0;
  6.         long timer = System.currentTimeMillis();
  7.         while(isRunning){
  8.             long now = System.nanoTime();
  9.             delta += (now - lastTime) / ns;
  10.             lastTime = now;
  11.             while(delta >= 1){
  12.                 tick();
  13.                 delta--;
  14.             }
  15.             if(isRunning)
  16.                 render();
  17.            
  18.             if(System.currentTimeMillis() - timer > 1000){
  19.                 timer += 1000;
  20.             }
  21.         }
  22.         stop();
  23.     }
  24.  
  25. private void tick(){
  26.    
  27. }
  28.  
  29. private void render(){
  30.    
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement