0

I have a little problem concerning JavaFX. I'm currently doing a User Interface for the ants algorithm.

I would like to chain multiple TranslateTransition in a loop. The problem is that only one of these transitions is displayed instead of all TranslateTransition in the order of creation.

while(condition){
   //some updates...
   TranslateTransition tt = new TranslateTransition(Duration.millis(2000), myObject);
   tt.play();
}

Is there a way to make sure that previous animations are finished before playing new ones ? Thank you !

jww
  • 97,681
  • 90
  • 411
  • 885
MrBushido
  • 47
  • 5
  • This question is somewhat related: [JavaFX Transition animation waiting](http://stackoverflow.com/questions/28093416/javafx-transition-animation-waiting), that question asks: "I need to create timeline or history of actions like ( placeVertex(x,y), moveVertex(newX,newY) etc. ) and iterate through (forward and backwards, automatically or manual)". – jewelsea Apr 23 '15 at 17:50

1 Answers1

0

Use the onFinished handler to launch the next transition. Define a method:

private TranslateTransition createNextTransition(Node myObject) {
    // some updates...
    TranslateTransition tt = new TranslateTransition(Duration.millis(2000), myObject);
    tt.setOnFinished(e -> {
        if (condition) {
            createNextTransition(myObject);
        }
    });
    tt.play();
}

And then just call it once:

createNextTransition(myObject);
James_D
  • 201,275
  • 16
  • 291
  • 322