4
\$\begingroup\$

Initially, I assumed that the developer has to implement the game loop because libgdx is a library - not an engine. But then I found out that Graphics has getDeltaTime() and getRawDeltaTime() so I assume that the game loop is already implemented.

If it is implemented, could someone explain what method libgdx uses? I'm mainly referring to this article. My guess is that it uses a semi-fixed time step? If that's the case, then why might getDeltaTime() "be smoothed over n frames?" How exactly is getDeltaTime() smoothed?

If the game loop is not implemented, what is the purpose of getDeltaTime() when you have getRawDeltaTime()?

\$\endgroup\$
4
  • \$\begingroup\$ This doesn't answer all of your question, but libGDX implements a render() loop for its rendering, and thus you can keep a time variable that you increment inside the render(delta time) method of your scene. When it passes your threshold, you can advance your game model and reset the time variable to 0. \$\endgroup\$
    – bazola
    Jul 16, 2015 at 19:32
  • \$\begingroup\$ The game loop is your render() function you override in your class which extends the ApplicationAdapterclass. getDeltaTime() is used for moving objects according to time elapsed instead of the frame rate which is not guaranteed to be consistent across all devices \$\endgroup\$
    – dimitris93
    Jul 16, 2015 at 19:33
  • \$\begingroup\$ @Shiro Any idea of how getDeltaTime() is smoothed? \$\endgroup\$ Jul 16, 2015 at 19:40
  • \$\begingroup\$ Regarding the smoothing used in getDeltaTime(), I've found this thread. getDeltaTime() seems to actually be an average of delta time values so I'm going to avoid it because it will cause the game to run at a variable/non-constant speed. Instead, I will use getRawDeltaTime(). \$\endgroup\$ Jul 16, 2015 at 19:57

1 Answer 1

1
\$\begingroup\$

LibGDX is formally a Framework and does implement the game loop for you. getDeltaTime() does smooth out over a number of frames. Instead you could use getRawDeltaTime(). I have seen some people get smoother results by capping the framerate to 30/60 instead of using getDeltaTime.

\$\endgroup\$
5
  • \$\begingroup\$ Any idea of how the game loop is implemented? For example: if I maintain 1 FPS for 60 seconds for example, does that mean getDeltaTime() and getRawDeltaTime() will return 1 second? The reason I ask is because if that's the case, I think I'm just going to replace it with my own game loop. \$\endgroup\$ Jul 16, 2015 at 21:25
  • \$\begingroup\$ @NathanN.Gonzalez What result would you like to get instead of 1 second ? Just do Math.min(Gdx.graphics.getDeltaTime(), 0.25f) \$\endgroup\$
    – dimitris93
    Jul 17, 2015 at 6:16
  • \$\begingroup\$ Take a look at what getRawDeltaTime() for windows/iOS and android returns. This is the latest as of now, 1.6.3 release. You should always use getDeltaTime(). Otherwise it would have been named getSmoothDeltaTime() instead. \$\endgroup\$
    – dimitris93
    Jul 17, 2015 at 6:22
  • \$\begingroup\$ For the android that "mean" was an average of the last 5 frames. Use getDeltaTime() and call it a day. LibGDX is a great framework. I doubt that their getDeltaTime() function was now well thought out. \$\endgroup\$
    – dimitris93
    Jul 17, 2015 at 6:32
  • \$\begingroup\$ Not sure about the amount of samples it gets smoothed but my guess is that it does return 1 after maintaining 1 FPS for 60 seconds. Smoothing the time over many frames would not give good results because one big frame drop would cause many frames to suffer from that if you use getDeltaTime(). I am curious too at the result you want. You can easily create your own smoothing with the getRawDeltaTime() by storing n frames and some basic math. I cannot think of a reason to implement your own gameloop just for frame smoothing. \$\endgroup\$
    – Madmenyo
    Jul 17, 2015 at 10:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .