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

Author Topic: Handling Events,  (Read 1660 times)

0 Members and 1 Guest are viewing this topic.

golgoth

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Handling Events,
« 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))

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Handling Events,
« Reply #1 on: November 10, 2010, 10:45:00 pm »
It could. But you shouldn't focus on such details, it doesn't change anything.
Laurent Gomila - SFML developer

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Handling Events,
« Reply #2 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
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

golgoth

  • Jr. Member
  • **
  • Posts: 99
    • View Profile
Handling Events,
« Reply #3 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Handling Events,
« Reply #4 on: November 11, 2010, 09:40:25 am »
Hmm ok well, I'll remember that when I rewrite the tutorials.
Laurent Gomila - SFML developer

 

anything