我正在做關於SDL遊戲開發的教程。找到一個輸入時,程序應該離開主循環,但它並不:SDL_PollEvent不起作用
SDL_Window* gWindow = NULL;
SDL_Surface* gScreenSurface = NULL;
SDL_Surface* gXOut = NULL;
int main(int argc, char* argv[]) {
if (!init()){
printf("Failed to initialize.\n");
}
else {
//Load media
if (!loadMedia()){
printf("Failed to load media.\n");
}
else {
//Main loop flag
bool quit = false;
//Event handler
SDL_Event e;
//While application is runnig
while (!quit){
//Handles events on queue
while (SDL_PollEvent(&e) != 0){
//User requests quit
if (e.type == SDL_QUIT){
quit = true;
}
}
//Aply the image
SDL_BlitSurface(gXOut, NULL, gScreenSurface, NULL);
//Update the surface
SDL_UpdateWindowSurface(gWindow);
}
}
}
//Free resources and close SDL
close();
return 0;
我試圖改變SDL_QUIT爲SDL_KEYPRESSED,但它也不起作用。任何想法爲什麼?
我拼錯了,我的意思是KEYDOWN,這也沒有奏效。現在解決了。但那麼我的問題是,究竟是什麼處理SDL_QUIT? – vandermies 2015-01-29 13:03:44
看看這個頁面 - https://wiki.libsdl.org/SDL_EventType#Remarks – Gumichan01 2015-02-05 11:16:33