Reputation: 1
JavaFX animation is choppy.
And when i use
stage.initStyle(StageStyle.TRANSPARENT)
animations become more choppy.
package com.test;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Pane root = new Pane();
Rectangle rect = new Rectangle(50,50,10,10);
Duration cycleDuration = Duration.millis(5000);
Timeline timeline = new Timeline(
new KeyFrame(cycleDuration,
new KeyValue(rect.widthProperty(),500,Interpolator.LINEAR))
);
timeline.setCycleCount(2000);
timeline.play();
root.getChildren().add(rect);
Scene scene = new Scene(root, 600, 650);
stage.initStyle(StageStyle.TRANSPARENT);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
How it works: https://youtu.be/UwoNByw-HYE
Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz 3.19 GHz
16,0 Gb
Windows 10
Java 19
Javafx 19
NVIDIA GeForce GTX 950 2Gb
I tried to make the same app with Qt QML, and it works really smooth and without ANY chopping. Here's the comparation with Qt QML (bottom) and JavaFX (top) https://youtu.be/YAcI05NkjAE. JavaFX is jerky compared to Qt QML
UPDATE: JavaFX app use GPU 10% and CPU 6% (with jerks)
Qt qml app use GPU 4% and CPU 2% (works prefect)
Upvotes: 0
Views: 205
Reputation: 10640
There definitely are visible glitches in the upper bar of the second video at irregular intervals of approximately one second length. Just concentrate on the right moving border of the bar. Some people just don't see or ignore them but others feel extremely disturbed by them. It seems to depend a bit on what you are used to. People who have a mobile or gaming background seem to be much more sensitive to such glitches than people with a primarily office PC background. Android once had project butter to overcome such glitches but JavaFX never did the same and still suffers from such glitches. (I know I won't make friends with this statement but it's true.) I also don't see anything obvious in your code that could directly improve the situation.
Edit: I have run your code on my Mac now and I have to admit that I do not see any glitches there. But I have seen the behaviour you describe very often myself. Of course it will always depend on your machine too.
Upvotes: 1