GetDeltaTime 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::Start( 70.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
Questions about GetDeltaTime? Click here. |