fixedStep method

void fixedStep([
  1. double dt = 1 / 60,
  2. int maxSubSteps = 10
])

Step the simulation forward keeping track of last called time to be able to step the world at a fixed rate, independently of framerate.

@param dt The fixed time step size to use (default: 1 / 60). @param maxSubSteps Maximum number of fixed steps to take per function call (default: 10). @see https://gafferongames.com/post/fix_your_timestep/ @example // Run the simulation independently of framerate every 1 / 60 ms world.fixedStep()

Implementation

void fixedStep([double dt = 1 / 60, int maxSubSteps = 10]) {
  final time = performance.now() / 1000; // seconds
  if (lastCallTime == null) {
    step(dt, null, maxSubSteps);
  } else {
    final timeSinceLastCalled = time - lastCallTime!;
    step(dt, timeSinceLastCalled, maxSubSteps);
  }
  lastCallTime = time;
}