简体   繁体   English

Javafx在每个时间轴“周期”之间暂停

[英]Javafx pause between each timeline “cycle”

At the moment I have a list with images which get displayed for a certain amount of time with a timeline. 目前,我有一个包含图像的列表,这些图像会随着时间轴显示一定时间。 However I want that after each there is a small pause where no image is displayed? 但是,我希望每次出现一个小暂停后都不会显示图像吗? Is there a way to achieve that behavior? 有没有办法实现这种行为?

Here is the Code I use so far: 这是我到目前为止使用的代码:

ImageView imView = new ImageView();

Duration timeBetweenImages = Duration.millis(10000);
Timeline timeline = new Timeline();

for (int i = 0; i < imageList.size(); i++) {
    Image image = imageList.get(i);
    Duration frameTime = timeBetweenImages.multiply(i);
    KeyFrame frame = new KeyFrame(frameTime, e -> imView.setImage(image));
    timeline.getKeyFrames().add(frame);
}

timeline.play();

As for now each picture is displayed 10 seconds. 目前,每张图片显示10秒。 I want that after the each 10 seconds there is a 1 second pause where no image is displayed. 我希望每10秒钟后有1秒钟的暂停时间,其中没有图像显示。

ImageView imView = new ImageView();

Duration timeBetweenImages = Duration.seconds(11);
Duration pauseTime = Duration.seconds(1);
Timeline timeline = new Timeline();

for (int i = 0; i < imageList.size(); i++) {
    Image image = imageList.get(i);
    Duration frameTime = timeBetweenImages.multiply(i);
    KeyFrame frame = new KeyFrame(frameTime, e -> imView.setImage(image));
    timeline.getKeyFrames().add(frame);

    Duration pauseFrameTime = timeBetweenImages.multiply(i+1).subtract(pauseTime);
    KeyFrame pauseFrame = new KeyFrame(pauseFrameTime, e -> imView.setImage(null));
    timeline.getKeyFrames().add(pauseFrame);
}

timeline.play();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM