[英]Allegro5 window won't close
我在快板中有一個窗口,當單擊頂部的 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){
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.