title: How to animate an UI without freeze when mouse is not over window?
body: <p>I'm building a game with some shapes that have to rotate, the problem is that, when the mouse go outside from the window it stops animate, and continue in background because when the mouse come again in the window it continues at the good moment</p>
  
  <p>I also tried using <code>Timer</code> and <code>TimerTask</code> but same problem</p>
  
  <p>I've build a <em>wonderful minimal and complete example</em> that explains that : </p>
  
  <pre><code>public class Tests extends Application {    
      public static void main(String[] args) {    launch(args);    }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          BorderPane pane = new BorderPane(); 
          pane.setPrefSize(300, 300);
          Arc arc = new Arc(150, 150, 50, 50, 0, 190.0);
          arc.setFill(Paint.valueOf("#f32f32"));
          Label label = new Label();
          pane.setCenter(arc);
          pane.setTop(label);
          primaryStage.setScene(new Scene(pane));
          primaryStage.show();
          primaryStage.centerOnScreen();
  
          Task&lt;Void&gt; task = new Task&lt;Void&gt;() {
              @Override
              protected Void call() throws Exception {
                  try {
                      Thread.sleep(2000);
                      Platform.runLater(() -&gt; label.setText("Start"));
                      for (int i = 0; i &lt; 360 * 5; i++) {
                          arc.setRotate(i);
                          Thread.sleep(5);
                      }
                      Platform.runLater(() -&gt; label.setText("Stop"));
                      Thread.sleep(2000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  return null;
              }
          };    
          new Thread(task).start();
          task.setOnSucceeded(e -&gt; { Platform.exit(); System.exit(0); });
      }
  }
  </code></pre>