1
我希望我的遊戲引擎能夠停止將鼠標移動到中心(用於偏航和俯仰相機計算)。我寫了一些應該照顧它的代碼,但鼠標在最小化時仍然移動。當SDL不具備焦點時,SDL不停止移動鼠標 - SDL C++
void mainLoop()
{
// This is the main logic portion of the engine
bool done = false;
bool visible = true;
SDL_Event event;
// Check to make sure we are supposed to quit
while(! done)
{
// Check for SDL events
while(SDL_PollEvent(& event))
{
// Figure out which event the user has triggered
switch (event.type)
{
case SDL_QUIT :
done = true;
break;
case SDL_ACTIVEEVENT:
if(event.active.state & SDL_APPACTIVE)
{
//If the application is no longer active
if(event.active.gain == 0)
{
visible = false;
}
else
{
visible = true;
}
}
case SDL_KEYDOWN :
// Check for user input
switch(event.key.keysym.sym)
{
// Escape - end the program
case SDLK_ESCAPE :
done = true;
break;
// Plus key - increase the speed of the camera
case SDLK_PLUS :
case SDLK_KP_PLUS :
if(camera.walkSpeed < 20.0f) { camera.walkSpeed += 1.0f; }
break;
// Minus key - decrease the speed of the camera
case SDLK_KP_MINUS :
case SDLK_MINUS :
if(camera.walkSpeed > 2.0f) {camera.walkSpeed -= 1.0f; }
break;
// F1 - save a TGA screenshot
case SDLK_F1:
saveScreenshot();
break;
// All other unassigned keys
default:
break;
}
}
}
// All events have been handled, now handle logic and rendering
if(visible)
{
updateFrame();
renderFrame();
}
}
}
當應用程序失去焦點時,它應該將可見標誌設置爲false,從而停止更新和渲染功能。有任何想法嗎?