SFML community forums

Help => Window => Topic started by: svento92 on December 11, 2019, 09:50:55 pm

Title: What is the most SFML compatible way to deal with the window events?
Post by: svento92 on December 11, 2019, 09:50:55 pm
So i'm developing a simple graphical Sudoku game. As most application I have the standard loop

Quote
    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
            if(menuChoice == 0) {
                menuChoice = mainMenu.handleEvents(event, window);
            }
        window.clear();
        if(menuChoice == 0) {
            mainMenu.drawMainMenu(window);
        }

As you'll notice from the code sample above i have two if statement if menuChoice == 0 The first decide what to draw based on the users choice in the main menu. The second says to draw the main menu if the user has not chosen any option yet.

Is there any good way of getting rid of this double if structure and still achieve the same goal?
Title: Re: What is the most SFML compatible way to deal with the window events?
Post by: Rosme on December 13, 2019, 07:55:06 pm
There's quite a few pattern that can be found here (http://"https://gameprogrammingpatterns.com/contents.html"). I suggest you read on the state pattern.