nextFrame method

  1. @override
Future<double> nextFrame()
override

Waits for the next frame. Returns a Future containing the time elapsed between frames (in seconds) This method needs to be implemented in subclasses

Implementation

@override
Future<double> nextFrame() async {
  var nextTimeStep = await window.animationFrame;

  if (previousTimeStep == 0) {
    previousTimeStep = nextTimeStep.toDouble();
  }

  var dt = nextTimeStep - previousTimeStep;
  previousTimeStep += dt;
  return dt / 1000; // in seconds
}