title: Game Loop updates too fast
body: <p>I want to create a start menue for a Pong clone where the ball in the background bounces off the edges. However the game loop updates to fast so the Coordinates of the ball are already out of the JFrame before you can see it and it moves to fast. I found that through sysouts. </p>
  
  <p>I guess it has something to do with threads but I am not sure.
  The main class calls this Class as a thread but the important part is in the class BackgroundBallMovement</p>
  
  <pre class="lang-java prettyprint-override"><code>package main;
  
  public class BackgroundBallMovement implements Runnable{
  
      private boolean running = true;
  
  
      @Override
      public void run() {
  
          long lastTime = System.nanoTime();
          final double ns = 1000000000.0 / 60;        
          double delta = 0;
  
          while(running) {
              long now = System.nanoTime();
              delta += (now - lastTime) / ns;
              while(delta &gt;= 1) {
                  update();
                  delta = 0;
                  System.out.println("X-Koordinate " + Var.ballX + " " + "Y-Koordinate " + Var.ballY);
              }
              render();
          }
      }
  
          //Spiellogik updaten
          private synchronized void update() {
              Var.ballX += 1;
              Var.ballY += 1;
  
          }
  
          //Objekte zeichnen
          private synchronized void render() {
               Var.drawStartMenue.repaint();
          }
  
  }
  </code></pre>