How to create multiple timers?
zero volt

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

Use two different event queues and two different event structs.

Mark Oates

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

Thanks! done!

Thread #615763. Printed from Allegro.cc