SFML community forums

Help => Window => Topic started by: golgoth on November 10, 2010, 10:13:09 pm

Title: Handling Events,
Post by: golgoth on November 10, 2010, 10:13:09 pm
Greetings,

On the tutorial Handling Events:

Code: [Select]
while (App.IsOpened())
{
    sf::Event Event;
    while (App.GetEvent(Event))
    {
        // Window closed
        if (Event.Type == sf::Event::Closed)
            App.Close();

        // Escape key pressed
        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();
    }
}


Shouldn’t be else if?

if (Event.Type == sf::Event::Closed)

else  if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Title: Handling Events,
Post by: Laurent on November 10, 2010, 10:45:00 pm
It could. But you shouldn't focus on such details, it doesn't change anything.
Title: Handling Events,
Post by: Groogy on November 10, 2010, 11:36:09 pm
Quote from: "Laurent"
It could. But you shouldn't focus on such details, it doesn't change anything.


Well it does change in that if "the first one is true then the second won't even execute" but it's only a tutorial on how SFML works, not C++.
Anyway if we are going to be like that we can just as well make it a switch to get optimizations from the compiler and etc. etc.

Like I said, It's a tutorial on SFML not optimizing C++ :P
Title: Handling Events,
Post by: golgoth on November 11, 2010, 01:38:12 am
I agree but it is a really important tutorial and It’s confusing the way it is written. It opens the possibility that two events could be process at the time. I’m pointing that out to make sure I’m not skipping events using a switch case.
Title: Handling Events,
Post by: Laurent on November 11, 2010, 09:40:25 am
Hmm ok well, I'll remember that when I rewrite the tutorials.