The fixed timestep approach

The Box2D world's inner simulation process advances every frame as the programmer orders in the step function. The specified amount of time will determine the speed of this simulation, having a direct impact on the game experience.

Delimiting a certain number of milliseconds might seem simple but the truth is that there are a good variety of ways to perform this.

The FIX YOUR TIMESTEP! article is the father of this recipe, so do not hesitate to read it at http://gafferongames.com/game-physics/fix-your-timestep/.

Getting ready

Run the code within Box2DFixedTimeStepSample.java, so you will see a scene where boxes fall from the sky and there are three buttons at the bottom. Each of them enable one of the three approaches covered ...

Get Libgdx Cross-platform Game Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.