1
if( ev.type == ALLEGRO_EVENT_TIMER)

This is the statement in the event loop to check if the incoming event is a timer event.

But all timers would generate this same event, so how do you have multiple timers going at once? How do you differentiate them?

porque_no_les_deux
  • 479
  • 1
  • 6
  • 18

3 Answers3

1

The event is a union. See all the properties here.

You want ev.timer.source (or ev.any.source).

Matthew
  • 47,584
  • 11
  • 86
  • 98
1

Here's a working example, Assuming you have two ALLEGRO_TIMERs(timer_one, timer_two) :

To respond to each timer:

if(ev.timer.source == timer_one) { //Timer one listener
//Code...
}


if(ev.timer.source == timer_two) { //Timer two listener
//Code...
}
Abdulaziz
  • 2,201
  • 1
  • 21
  • 35
0

I was having an issue with this for the longest time and I found out I just forgot to include al_start_timer(alTimer); in my update. Stupid mistake but it could cost you some time if you forget it.

David Ansermot
  • 6,052
  • 8
  • 47
  • 82