How should I handle checking if an event, such as closing the window, has occurred if I also need to be able to go through the game loop?
int main()
{
MyGame game;
game.setIsRunning(true);
sf::RenderWindow gameWindow(sf::VideoMode(MyGame::width * MyGame::scale, MyGame::height * MyGame::scale), "My Game!");
while (gameWindow.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (gameWindow.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
gameWindow.close();
}
}
while ( game.getIsRunning() == true)
{
game.gameLoop();
}
return 0;
If I'm constantly running through a loop while the window is open I'll never get to the game loop until the window is closed. Sorry if this is a stupid question, I'm still new to SFML and game programming in general. Thanks for any advice or help.