So I was making a program in JavaFX where I use an AnimationTimer. I need to be able to pause the AnimationTimer whenever I want, so someone recommended using Timelines on one of my other Stackoverflow questions. However, it seems that you can only pause an AnimationTimer for a given amount of time once. For example, while the following code should pause the AnimationTimer for a total of 1 second over four equal intervals, it only pauses it once:
public Timeline createPauseTimerTimeline(AnimationTimer timer, Duration duration) {
return new Timeline(
new KeyFrame(Duration.ZERO, event -> timer.stop()),
new KeyFrame(duration, event -> timer.start())
);
}
// Inside some other method:
Timeline delay = createPauseTimerTimeline(timer, new Duration(250));
/* blah blah */
delay.playFromStart();
/* blah blah */
delay.playFromStart();
/* blah blah */
delay.playFromStart();
/* blah blah */
delay.playFromStart();
/* blah blah */
How can I fix the code so that I can pause the AnimationTimer for a set number of seconds whenever I want? Any help would be greatly appreciated.