GetDeltaTime

static float GetDeltaTime();

Get the elapsed game time between this and the previous frame.

The speed regulation requires you to multiply all speed and position and rotational changes with the delta time.

Using this function requires to start the fps counter before the game loop starts and to call FpsCounter::NewFrameStarted() in the beginning of each frame.

Note that the fps counter has to be started before calling this function.

Examples

float playerX, playerY;
float playerSpeedX, playerSpeedY;
float playerAccelerationX, playerAccelerationY;

// The default fps is 70.0 //
FpsCounter::Start70.0 );

while( gameRunning ) {
  // Tell OpenLayer that a new game frame has started. //
  FpsCounter::NewFrameStarted();
  
  // Get the delta time //
  float deltaTime = FpsCounter::GetDeltaTime();
  
  // Change the speed of the player according to the acceleration //
  playerSpeedX += deltaTime * playerAccelerationX;
  playerSpeedY += deltaTime * playerAccelerationY;
  
  // Move the player //
  playerX += deltaTime * playerSpeedX;
  playerY += deltaTime * playerSpeedY;
  
  // Other game loop code //
}


Other functions of the class FpsCounter
Start
Starts the FPS counter
NewFrameStarted
Tells OpenLayer that a new game frame has started
GetDeltaTime
Get the elapsed game time between this and the previous frame
GetFps
Returns the frames per second the program runs at
Pause
Pauses the FPS counter
Resume
Resumes the paused FPS counter


Questions about GetDeltaTime? Click here.