xXxxX
xXxxX

Reputation: 205

Box2D and Xcode

I'm develop a game using LevelHelper (SpriteKit + Box2D) and I ran into a problem.

Box2D depends on the count of FPS. Those if the 60FPS, then the body moves at a speed of 10 meters per second, if 30FPS, then at a speed of 5 meters per second. It is necessary that regardless of the count of FPS was a constant speed.

Is there any solution to unbind Box2D from the count of FPS?

Upvotes: 1

Views: 154

Answers (1)

Louis Langholtz
Louis Langholtz

Reputation: 3123

In regards to simulated time, Box2D only depends on what you have the world step's time delta set to. If you have the time delta set to 1/60th of a second, then it would match up with a 60FPS display refresh but the time delta can be other values.

Generally speaking, the simulation gets more accurate as the time delta gets smaller. So if instead of of using world steps that simulated 1/60th of a second you used steps that simulated 1/120th of a second you'd have a more accurate simulation. Using a smaller time delta, also allows bodies' max speeds (in distance traveled per simulated second) to be faster.

It's up to the Box2D library user to figure out how to coordinate the world steps with the display refresh. Just know that varying the world step time -- like by using real-time elapsed between calls to the world step method -- may cause unrealistic physics effects. So while varying the world step time delta at run-time during a simulation is possible, I wouldn't recommend it.

Upvotes: 2

Related Questions