Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How to create multiple timers?

This thread is locked; no one can reply to it. rss feed Print
How to create multiple timers?
zero volt
Member #15,793
November 2014

So far I did this :

#SelectExpand
1ALLEGRO_TIMER *timer1 = NULL; 2ALLEGRO_TIMER *timer2 = NULL; 3 4... 5 6timer1 = al_create_timer(1.0 / 60); 7timer2 = al_create_timer(1.0 / 20); 8 9... 10 11al_register_event_source(event_queue, al_get_timer_event_source(timer1)); 12al_register_event_source(event_queue, al_get_timer_event_source(timer2)); 13 14... 15 16al_start_timer(timer1); 17al_start_timer(timer2); 18 19... 20 21if(ev.type == ALLEGRO_EVENT_TIMER) { 22 // ??? 23}

How to check if timer1 has ticked or timer2 has ticked and then do actions?

RPG Hacker
Member #12,492
January 2011
avatar

Use two different event queues and two different event structs.

Mark Oates
Member #1,146
March 2001
avatar

You can check the .timer.source subfield of the ALLEGRO_EVENT.

#SelectExpand
1switch (ev.type) 2{ 3 case ALLEGRO_TIMER: 4 if (ev.timer.source == timer1) 5 { 6 // do things for timer1 7 } 8 else if (ev.timer.source == timer2) 9 { 10 // do things for timer2 11 } 12 break; 13 default: 14 break; 15}

zero volt
Member #15,793
November 2014

Thanks! done!

Go to: