Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make JavaFX wait until Timeline finishes

I have two timeline which runs inside one function, they are both affect one object, problem is when I play first timeline, other timeline also starts within next line of code, how can I wait until fist timeline finish then play another timeline?

like image 558
Yashar Avatar asked Mar 14 '15 20:03

Yashar


1 Answers

Timeline.play() is asynchronous—it starts the animation in the background and returns immediately. There are several ways to achieve sequential execution. Which fits best depends on your use case.

  1. Use just one Timeline and move the KeyFrames from your second timeline to the first one, with adjusted start duration.
  2. Start the second timeline when the first one is finished: timeline1.setOnFinished(e -> timeline2.play()).
  3. If you can, use Transitions instead of Timelines and wrap them in a SequentialTransition.
like image 166
Tomas Mikula Avatar answered Oct 22 '22 15:10

Tomas Mikula