我目前正在浏览 SDL2 的 Lazy Foo 教程(我在 Linux 机器上执行此操作),并且遇到了某种错误,其中包含SDL_PollEvent
在我的主循环中似乎可以防止SDL_UpdateWindowSurface
从实际更新来看。如果我离开SDL_PollEvent
循环输出后,加载的 bmp 可以正常显示。但是,如果我包括SDL_PollEvent
循环甚至调用SDL_PollEvent
,那么窗口永远不会更新图像。其他一切似乎都运转良好SDL_PollEvent
正确地对事件进行排队并且循环正确地处理事件,但由于某种原因,包含的内容之间存在视觉差异SDL_PollEvent
vs. 忽略它。
使用提供的代码第 03 课:事件驱动编程:
此循环无法更新窗口:
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
}
//Apply the image
SDL_BlitSurface( gXOut, NULL, gScreenSurface, NULL );
//Update the surface
SDL_UpdateWindowSurface( gWindow );
}
此循环成功使用加载的图像更新窗口:
while( !quit )
{
//Apply the image
SDL_BlitSurface( gXOut, NULL, gScreenSurface, NULL );
//Update the surface
SDL_UpdateWindowSurface( gWindow );
}
但它停止工作包含一个单一的调用SDL_PollEvent
:
while( !quit )
{
SDL_PollEvent(&e);
//Apply the image
SDL_BlitSurface( gXOut, NULL, gScreenSurface, NULL );
//Update the surface
SDL_UpdateWindowSurface( gWindow );
}