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

Author Topic: Using more than one Event in the main function  (Read 1789 times)

0 Members and 1 Guest are viewing this topic.

nullGrind

  • Newbie
  • *
  • Posts: 23
    • View Profile
Using more than one Event in the main function
« on: December 05, 2009, 09:21:13 pm »
Hallo

I try to use 2 Events in the main function. The Event for closing down the window does not work when the control event is in front of it. When i disable the control event the closing event works...
Is there a way to have more than one event in the main function?

Code: [Select]

        sf::Event Control;
        while (App.GetEvent(Control)) {
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Left))
                bool left = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Left))
                bool left = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Right))
                bool right = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Right))
                bool right = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Up))
                bool up = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Up))
                bool up = false;
            if ((Control.Type == sf::Event::KeyPressed) && (Control.Key.Code == sf::Key::Down))
                bool down = true;
            if ((Control.Type == sf::Event::KeyReleased) && (Control.Key.Code == sf::Key::Down))
                bool down = false;
        }

        sf::Event Event;
        while (App.GetEvent(Event)) {
            if (Event.Type == sf::Event::Closed)
                App.Close();
            if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
                App.Close();
        }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Using more than one Event in the main function
« Reply #1 on: December 05, 2009, 09:28:55 pm »
No, because your first loop will pop all the events and leave nothing for the second one.

There's no point doing what you do, why do you want to use more than one event loop?
Laurent Gomila - SFML developer

nullGrind

  • Newbie
  • *
  • Posts: 23
    • View Profile
Using more than one Event in the main function
« Reply #2 on: December 05, 2009, 09:35:51 pm »
oh thanks Laurent

i didnt realise the functionality of events. now i just write my whole event stuff in one event.