JavaFX : Rotated animation delay between cycles

风格不统一 提交于 2019-12-30 18:55:58

问题


I've created an animation for an ImageView based on a RotatedTranstion using the following code :

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 i.e there is a small delay (pause) between animation cycles.

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.


回答1:


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).

To remove this, just set the interpolator to Interpolator.LINEAR:

rotateTransition.setInterpolator(Interpolator.LINEAR);



回答2:


The timing for acceleration and deceleration at each Transition cycle is controlled by the Interpolator. The default Interpolator used by Transition is Interpolator.EASE_BOTH.

You want linear interpolation so add this to your code:

rotateTransition.setInterpolator(Interpolator.LINEAR);


来源:https://stackoverflow.com/questions/36084987/javafx-rotated-animation-delay-between-cycles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!