Playing nice with your application neighborhood
Now what we learned in the last part is indeed handy, but it has got its problem. What if the user tabs out and tries to interact with the other applications that are running in the background? We would be constantly forcing the mouse back to the center of our window, making it impossible to do anything else than playing our game.
Believe it or not, this is actually very annoying for a lot of people, including ourselves. When we are debugging our application, this behavior will make it impossible to work with the IDE in the background. We have to detect when the user doesn't want to interact with us anymore and behave properly.
This is where events come in again. If you remember, we had the event types sf::Event::GainedFocus
and sf::Event::LostFocus
that notify the application as soon as the window gains or loses focus:
void Game::processEvents() { sf::Event event; while(mWindow.pollEvent(event)) { if (event.type == sf::Event...