【发布时间】:2017-10-04 17:10:14
【问题描述】:
我想显示一个精灵动画,使用 ImageView 作为图像的容器和 TimeLine 来切换 imageview 中的图像:
private ImageView imgView;
...
public void init(Image[] images) {
this.imgView = new ImageView(images[0]);
Timeline timeLine = new Timeline();
Collection<KeyFrame> frames = timeLine.getKeyFrames();
for (Image img : images)
frames.add(new KeyFrame(Duration.millis(256), e -> imgView.setImage(img)));
timeLine.setCycleCount(Timeline.INDEFINITE);
timeLine.play();
}
ImageView 被渲染,但卡在动画的某些图像上(甚至不是第一个)。就像我只会将一张图像放入 imageview 并且永远不会更改它。 我在 ImageView 的 imageproperty 中添加了一个 ChangeListener,输出 imageview 的当前图像。它确实在根据需要进行更改,但仍然只渲染了一张图像。图像肯定不同,我仔细检查了。为什么imageproperty改变后imageview没有更新?
【问题讨论】: