Wiki Page Content

Differences between revisions 5 and 6
Revision 5 as of 2013-08-08 18:27:35
Size: 598
Editor: Sam Lantinga
Comment:
Revision 6 as of 2013-11-18 18:10:33
Size: 833
Comment: add example
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
You can add your code example here unsigned int lastTime = 0, currentTime;
while (!quit) {
  // do stuff
  // ...

  // Print a report once per second
  currentTime = SDL_GetTicks();
  if (currentTime > lastTime + 1000) {
    printf("Report: %d\n", variable);
    lastTime = currentTime;
  }
}

SDL_GetTicks

Use this function to get the number of milliseconds since the SDL library initialization.

Syntax

Uint32 SDL_GetTicks(void)

Return Value

Returns an unsigned 32-bit value representing the number of milliseconds since the SDL library initialized.

Code Examples

unsigned int lastTime = 0, currentTime;
while (!quit) {
  // do stuff
  // ...

  // Print a report once per second
  currentTime = SDL_GetTicks();
  if (currentTime > lastTime + 1000) {
    printf("Report: %d\n", variable);
    lastTime = currentTime;
  }
}

Remarks

This value wraps if the program runs for more than ~49 days.


CategoryAPI, CategoryTimer

None: SDL_GetTicks (last edited 2013-12-07 13:13:16 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit