快板5窗口无法关闭

Allegro5 window won't close

本文关键字:窗口 快板      更新时间:2023-10-16

我在allegro中有一个窗口,当点击顶部的X按钮时,它应该会关闭。我有它工作所需的所有代码,但它不会。

要初始化显示器,我有这个:

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

要初始化事件队列,我有这样的:

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));

为了响应输入并使用或关闭窗口进行渲染,我有这样的:

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;
    }
}

我认为您需要更改行:

else if (ev.type == ALLEGRO_EVENT_KEY_DOWN){

else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){