title: How to reverse animation after it has finished?
body: <p>I have a list of animations and I want to be able to play them by clicking on a "next" button and playing them back by clicking a "previous" button. So I can play the first animation, then play the 2nd animation, then play the 2nd animation backwards and reach the position like after playing the first animation only.</p>
  
  <p>My problem is that I can't reverse the animation after it's finished. I know that I can set <code>autoReverse</code> but then each animation will reverse immediately. </p>
  
  <p>Here is an example for one animation:</p>
  
  <pre><code>import javafx.animation.TranslateTransition;
  import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.HBox;
  import javafx.scene.layout.Pane;
  import javafx.scene.layout.VBox;
  import javafx.scene.paint.Color;
  import javafx.scene.shape.Circle;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  
  public class AnimTest extends Application {
  
      @Override
      public void start(Stage stage) throws Exception {
          Circle c = new Circle(5, Color.RED);
          TranslateTransition move = new TranslateTransition(Duration.seconds(2), c);
          move.setByX(10);
          move.setByY(10);
  
          Button next = new Button("Next");
          Button previous = new Button("Previous");
          next.setOnAction(e -&gt; {
              move.setRate(1);
              move.play();
          });
          previous.setOnAction(e -&gt; {
              move.setRate(-1);
              move.play();
          });
  
          Pane p = new Pane(c);
          p.setPrefSize(50, 50);
          HBox buttons = new HBox(next, previous);
          VBox root = new VBox(p, buttons);
          stage.setScene(new Scene(root));
          stage.show();
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  </code></pre>
  
  <p>After pressing "next" I want "previous" to move the ball back to its original position (so effectively x by -10 and y by -10) and not playing the "following" animation in reverse.</p>
  
  <p>In practice, my animations animate different objects in the scenegraph and they can be parallel/sequential transitions. For the list I keep a current location index <code>i</code> and doing:</p>
  
  <pre><code>    next.setOnAction(e -&gt; {
          Animation move = list.get(i);
          move.setRate(1);
          move.play();
          i++;
      });
      previous.setOnAction(e -&gt; {
          i--;
          Animation move = list.get(i);
          move.setRate(-1);
          move.play();
      });
  </code></pre>
  
  <p>in an attempt to reverse the previous animation.</p>
  
  <p>How can I do this?</p>
  
  <p>To clarify, my list is of <code>Animation</code>. The <code>TranslateTransition</code> was just an example.</p>