Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Time

Add this in your code:

#include <engine/time/time.h>

Description

Class to get time information (Delta time, elapsed time).

Values are updated every frame.

Static methods


GetTime

Get total scaled elapsed time.
Start at 0 when the game starts.

float GetTime()

Code sample:

float timeA = Time::GetTime(); // = 0.0f
Time::SetTimeScale(0.5f);

// 2 seconds later...

float timeB = Time::GetTime(); // = 1.0f

GetUnscaledTime

Get total unscaled elapsed time (not affected by time scale).
Start at 0 when the game starts.

float GetUnscaledTime()

Code sample:

float timeA = Time::GetUnscaledTime(); // = 0.0f
Time::SetTimeScale(0.5f);

// 2 seconds later...

float timeB = Time::GetUnscaledTime(); // = 2.0f

GetDeltaTime

Get scaled delta time, which is the time elapsed since the last frame * time scale.

float GetDeltaTime()

Code sample:

// Game running at 60 fps with a time scale of 1.0f
float timeA = Time::GetDeltaTime(); // = 0.0166f

// Game running at 60 fps with a time scale of 0.5f
float timeA = Time::GetDeltaTime(); // = 0.0083f

GetUnscaledDeltaTime

Get unscaled delta time which is the time elapsed since the last frame (not affected by time scale).

float GetUnscaledDeltaTime()

Code sample:

// Game running at 60 fps with a time scale of 1.0f
float timeA = Time::GetUnscaledDeltaTime(); // = 0.0166f

// Game running at 60 fps with a time scale of 0.5f
float timeA = Time::GetUnscaledDeltaTime(); // = 0.0166f

GetTimeScale

Get time scale (Speed of the game).

float GetTimeScale()

Code sample:

Time::SetTimeScale(0.4f);
float timeScale = Time::GetTimeScale(); // = 0.4f

SetTimeScale

Get time scale (Speed of the game).

Parameters:

  • timeScale: Time scale (minium 0)
void SetTimeScale(float timeScale)

Code sample:

Time::SetTimeScale(0.4f);