Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Chainging timer value in the middle of my game loop

This thread is locked; no one can reply to it. rss feed Print
Chainging timer value in the middle of my game loop
TeachMeHowToPro
Member #15,892
February 2015

Hello!
My question is simple: How can i change my game loop's one ( or more of the timer i use ) without getting out of the game loop?

I was thinking of something like this:

if(ShouldChangeTimer){
al_stop_timer(timer);
al_destroy_timer(timer);
timer=al_create_timer(NewTimerValue);
al_start_timer(timer);
}

But do i need to unregister and register the event source once the timer has changed?
Something like:

if(ShouldChangeTimer){
al_stop_timer(timer);
al_unregister_event_source(event_queue,al_get_timer_event_source(timer));
al_destroy_timer(timer);
timer=al_create_timer(NewTimerValue);
al_register_event_source(event_queue,al_get_timer_event_source(timer));
al_start_timer(timer);
}

Is this the correct way to change a timer in the middle of my game? What do you suggest for chainging timer values?

Edgar Reynaldo
Member #8,592
May 2007
avatar

Go to: