JavaFX: Rotating Animation Delay Between Loops

I created an animation for ImageView based on 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(); 

The result is the following animation:

Rotation in action

As you may have noticed in the animated gif, the animation is not continuous, that is, there is a slight delay (pause) between the animation cycles.

I tried to look at the API, but I can’t understand what causes this delay and how I can get rid of it.

+5
source share
2 answers

The obvious pause between each cycle is caused by interpolator , which by default uses Interpolator.EASE_BOTH (therefore, it slows down at the end of each cycle and accelerates at the beginning).

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

 rotateTransition.setInterpolator(Interpolator.LINEAR); 
+5
source

The time for acceleration and deceleration in each Transition cycle is controlled by Interpolator . The default Interpolator used by Transition is Interpolator.EASE_BOTH .

You need linear interpolation, so add this to your code:

 rotateTransition.setInterpolator(Interpolator.LINEAR); 
+3
source

Source: https://habr.com/ru/post/1245313/


All Articles