Remove a timer created with SDL_AddTimer().
Defined in SDL_timer.h
id | the ID of the timer to remove |
Returns SDL_TRUE if the timer is removed or SDL_FALSE if the timer wasn't found.
This function is available since SDL 2.0.0.
// Function to be called after a certain time
Uint32 callback(Uint32 interval, void* name) {
printf("Hello %s!\n", (const char*)name);
return 0;
}
/* ... */
// Initialize timer
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
SDL_Log("SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) failed: %s", SDL_GetError());
}
/* ... */
// Set timer to 1 second
SDL_TimerID timerID = SDL_AddTimer(1000, callback, "SDL");
// Main loop
SDL_bool quit;
while(!quit) {
/* ... */
}
// Remove timer after main loop
SDL_RemoveTimer(timerID);