0

I want to write a game engine with JavaFX. In my current tests I am using a javafx.animation.Timeline as my gameloop. The thing I don't like about the Timeline is that if the rendering process takes longer than the time between frames, the Timeline is trying to catch up and executes the code inside the loop like 30 times before displaying the rendered content once. After the frame has been displayed once, the same thing happen again.

Is there any way to make a gameloop without a Timeline or at least a way to detect whenever the Timeline is lagging behind, so I can lower the framerate if that happens?

Quijx
  • 366
  • 1
  • 10
  • What type of gameloop is it? Are you trying to fetch data from somewhere or is it just related to the UI? – ItachiUchiha Mar 14 '15 at 12:08
  • @ItachiUchiha I am drawing to the `GraphicsContext` of a `Canvas` inside the `EventHandler` of the `KeyFrame` used in the `Timeline`. – Quijx Mar 14 '15 at 12:21
  • 2
    The usual approach for a game loop is an [`AnimationTimer`](http://docs.oracle.com/javase/8/javafx/api/javafx/animation/AnimationTimer.html). Also see Stephen van Impe's blog: [post 1](http://svanimpe.be/blog/game-loops.html) and [post 2](http://svanimpe.be/blog/game-loops-fx.html) – James_D Mar 14 '15 at 12:46
  • @James_D Thanks a lot! I tried with `AnimationTimer`and it works a lot better now. Would you mind to post that as an answer? Maybe it helps someone else. – Quijx Mar 14 '15 at 13:34
  • Possible duplicate of [How does AnimationTimer work?](https://stackoverflow.com/questions/16853711/how-does-animationtimer-work) – Ishan Srivastava Jul 19 '17 at 09:34

0 Answers0