简体   繁体   English

JavaFX:循环之间的旋转动画延迟

[英]JavaFX : Rotated animation delay between cycles

I've created an animation for an ImageView based on a RotatedTranstion using the following code : 我使用以下代码为基于RotatedTranstion的ImageView创建了动画:

ImageView icon = ImageCache.getImage("refresh.png");
RotateTransition rotateTransition = new RotateTransition(Duration.millis(2000), icon);
rotateTransition.setByAngle(360.0);
rotateTransition.setCycleCount(Timeline.INDEFINITE);

rotateTransition.play();

This results in the following animation : 这将产生以下动画:

Rotation in Action 轮换行动

As you may have noticed in the animated gif, the animation is not continuous ie there is a small delay (pause) between animation cycles. 就像您在动画gif中注意到的那样,动画不是连续的,即动画周期之间的延迟很小(暂停)。

I've tried to look at the API but can't figure out what causes this delay and how i can get rid of it. 我试图看一下API,但无法弄清楚是什么原因造成了这种延迟以及如何摆脱这种延迟。

The apparent pause between each cycle is caused by the interpolator , which by default uses Interpolator.EASE_BOTH (so it decelerates at the end of each cycle and accelerates at the beginning). 每个周期之间的明显停顿是由interpolator引起的,默认情况下使用Interpolator.EASE_BOTH (因此,它在每个周期的末尾减速并在开始时加速)。

To remove this, just set the interpolator to Interpolator.LINEAR : 要删除它,只需将插值器设置为Interpolator.LINEAR

rotateTransition.setInterpolator(Interpolator.LINEAR);

The timing for acceleration and deceleration at each Transition cycle is controlled by the Interpolator . 每个Transition周期的加速和减速时间均由Interpolator器控制。 The default Interpolator used by Transition is Interpolator.EASE_BOTH . Transition使用的默认Interpolator器是Interpolator.EASE_BOTH

You want linear interpolation so add this to your code: 您需要线性插值,因此将其添加到代码中:

rotateTransition.setInterpolator(Interpolator.LINEAR);

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

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