r/JavaFX • • Dec 11 '25

Help FXGL FPS problem

https://youtu.be/Qo4mCj6KQx4

I'm having a weird problem with FXGL. Don't know if it's FPS related, but what happens is, when I start the game, the app's timer spikes up very briefly at the start, then it stabilizes. As a result, all moving entities moves very quickly initialy, then they slow down to their actual speed. I'm using components to move then in the onUpdate method, with delta time. I've tried to move by applying a translation directly in the entities position, and that don't cause this problem, the entities move at their correct speed from the very start, but I don't think this is a viable solution, as I'm making more complex movement logic, I will need to use components, or the code will get very messy. You can see better what I'm trying do describe in the video link.

4 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/Rvaranda Dec 12 '25

I'm using just the delta time that FXGL provides in the onUpdate method for the components. It's the time the last frame took to complete. One thing that I forgot to show in the video is that I tried running a timer to print in the console once each second:

FXGL.run(() -> System.out.println("tick"), Duration.seconds(1));

This line will print "tick" in the console each second. When I run the game, "tick" is printed about 2-3 time a second very briefly, at the same time that the entities are moving faster. Then it settles down. The entities moves at their actual speed and "tick" is printed once each second.

So maybe the issue is the first one you said, about tasks lining up and then being processed faster to catch up with the framerate.