SHARE
TWEET

Untitled

a guest Mar 26th, 2020 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     final int FRAMERATE = 60;
  2.  
  3.     @Override
  4.     public void run() {
  5.         long lastTime = System.nanoTime();
  6.         long frameTime = 1_000_000_000 / FRAMERATE;
  7.  
  8.         while (true) {
  9.             long currentTime = System.nanoTime();
  10.             long updateTime = currentTime - lastTime;
  11.             lastTime = currentTime;
  12.            
  13.             world.getProj().deplaceX(this);
  14.             world.getProj().deplaceY(this);
  15.             world.gravityAction(updateTime);
  16.             repaint();
  17.  
  18.            
  19.             long sleepDuration = (frameTime - updateTime) / 1_000_000;
  20.             if (sleepDuration > 0) {
  21.                 try {
  22.                     Thread.sleep(sleepDuration);
  23.                 } catch (InterruptedException e) {
  24.                     e.printStackTrace();
  25.                 }
  26.             }
  27.         }
  28.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top