-2

I have a window in allegro, and when the X button at the top is clicked it should close. I have all the necessary code for it to work, but it won't.

To initialize the display I have this:

display = al_create_display(dwidth, dheight);
    if (!display){
        error.message("Fatal Error", "ERROR:", "DISPLAY HAS FAILED TO BE CREATED");
    }

To initialize the event queue I have this:

ALLEGRO_EVENT_QUEUE *event_queue = NULL;

event_queue = al_create_event_queue();
if (!event_queue){
    error.message("Fatal Error", "ERROR:", "EVENT QUEUE HAS FAILED TO BE CREATED");
}

al_register_event_source(event_queue, al_get_display_event_source(display));

And to respond to the input and render with or close the window I have this:

al_start_timer(tick);
while (true)
{
    //handle input and timer
    ALLEGRO_EVENT ev;
    al_wait_for_event(event_queue, &ev);

    if (ev.type = ALLEGRO_EVENT_TIMER){
        redraw = true;
        //put all fps dependant function here

    }
    else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
        break;
    }

    if (redraw && al_is_event_queue_empty(event_queue)) {
        //FPS independant functions go here


        al_flip_display();
        al_clear_to_color(al_map_rgb(255, 255, 255));
        redraw = false;
    }
}

1 Answers1

1

I think you need to change the line:

else if (ev.type == ALLEGRO_EVENT_KEY_DOWN){

to

else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
TriskalJM
  • 2,393
  • 1
  • 19
  • 20
  • That was a typo, I copied it from the wrong file. But I managed to fix it anyways while changing it, so thanks I guess. –  Mar 31 '16 at 21:12