SFML community forums
Help => Window => Topic started by: golgoth on November 10, 2010, 10:13:09 pm
-
Greetings,
On the tutorial Handling Events:
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))
…
-
It could. But you shouldn't focus on such details, it doesn't change anything.
-
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
-
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.
-
Hmm ok well, I'll remember that when I rewrite the tutorials.