samuelmadethis
samuelmadethis

Reputation: 79

JavaFX Canvas Efficient Animations

I am working with a JavaFX Canvas animating the motion of Shape and Polyline objects over time. Currently, every frame, the location of X and Y of each Shape or Polyline in a list is edited as required and the object is moved. This results in about 20-30fps

An earlier approach I have tried simply clears the canvas every frame and redraws each object again. No lists of objects are stored. this results in 60fps

This second method seems to be a far messier approach yet results in a far better framerate.

Are there any best practices or recommended ways to animate on a JavaFX canvas? Anything clean and recommended yet results in a good framerate?

Many Thanks

Upvotes: 0

Views: 1019

Answers (1)

mipa
mipa

Reputation: 10640

I just gave a talk about these issues at the JavaLand conference. It is indeed true that for general animations with path based shapes (like Polyline and Polygon) using the Canvas is currently the fastest standard option. This is due to a bug in JavaFX which can make such animations via the scene graph slow. I have reported this issue and a bug fix is on the way.

https://bugs.openjdk.java.net/browse/JDK-8178521

In this JIRA issue I refer to hardware versus software rendering but it also affects scene graph versus canvas rendering because the canvas does not seem to be affected by this bug.

Upvotes: 2

Related Questions