FpsCounter

Helps to make the program to run at the same speed in regardless of the fps and calculates the fps.

To regulate the speed of the program you should start the fps counter before the game loop starts. Then in the beginning of each loop you should call FpsCounter::FpsCounter/NewFrameStarted.html">NewFrameStarted() and to get the delta time using FpsCounter::FpsCounter/GetDeltaTime.html">GetDeltaTime(). Then you should multiply all the position, speed and rotational changes by the delta time.

Examples

// Example of how to make the game to run at the same speed regardless of the fps //

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::FpsCounter/NewFrameStarted.html">NewFrameStarted();
  
  // Get the delta time //
  float deltaTime = FpsCounter::FpsCounter/GetDeltaTime.html">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 //
}



Member functions
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 FpsCounter? Click here.