【问题标题】:Allegro5 window won't closeAllegro5 窗口不会关闭
【发布时间】:2016-03-31 20:21:06
【问题描述】:

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

【问题讨论】:

    标签: c++ allegro5


    【解决方案1】:

    我认为你需要换行:

    else if (ev.type == ALLEGRO_EVENT_KEY_DOWN){
    

    else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE){
    

    【讨论】:

    • 那是一个错字,我从错误的文件中复制了它。但我还是设法在更改它的同时修复它,所以我猜是谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    相关资源
    最近更新 更多