Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: What is the most SFML compatible way to deal with the window events?  (Read 3353 times)

0 Members and 1 Guest are viewing this topic.

svento92

  • Newbie
  • *
  • Posts: 6
    • View Profile
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?

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: What is the most SFML compatible way to deal with the window events?
« Reply #1 on: December 13, 2019, 07:55:06 pm »
There's quite a few pattern that can be found here. I suggest you read on the state pattern.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

 

anything