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?
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.
Timeline
and move the KeyFrame
s from your second timeline to the first one, with adjusted start duration.timeline1.setOnFinished(e -> timeline2.play())
.Transition
s instead of Timeline
s and wrap them in a SequentialTransition
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With