Logging & timeSDL 3.2

SDL_GetTicks

Milliseconds since SDL started. Simple, but too coarse to time a frame.

Signature

Uint64 SDL_GetTicks(void);

How it works

A frame at 144 Hz lasts about 6.9 ms. Whole milliseconds round that to 6 or 7, an error of up to 14% that shows up as jittery movement. Use SDL_GetTicksNS (nanoseconds, same clock) for frame timing, and SDL_GetTicks for coarse things such as "show the hint after 3 seconds".

The value is a 64-bit integer, so unlike SDL2's 32-bit version it does not wrap around after 49 days.

Return value

Milliseconds since SDL was initialized.

Example

example.cpp
1Uint64 shownAt = SDL_GetTicks();
2// ...
3if (SDL_GetTicks() - shownAt > 3000) showHint = true;
Official SDL wiki