Start with a boolean, this will be used for an update statement at the end. Another variable was used for the FPS in case you change it later, so you don't have to change it throughout the program.
bool draw = true;
const int FPS = 60;
Then make an event queue pointer and a timer pointer. 1 / 60 means 60 times a second.
ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS);
Register the timer into the event queue and start the timer. Putting anything other than the game loop after this statement might fuck up the timer.
al_register_event_source(event_queue, al_get_timer_event_source(timer));//put the timer into the queue
al_start_timer(timer);
Inside the game loop, make the event.
ALLEGRO_EVENT events;
al_wait_for_event(event_queue, &events);
If the event timer ticks into the queue, update the draw variable.
if(events.type == ALLEGRO_EVENT_TIMER)
{
draw = true;//only draw if something updated
}
If something changed the update the graphics.
if(draw)
{
do all your graphics stuff here
}
No comments:
Post a Comment