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

Author Topic: [SFML 2.0]Problem with repeating buttons and events.  (Read 12766 times)

0 Members and 1 Guest are viewing this topic.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: [SFML 2.0]Problem with repeating buttons and events.
« Reply #15 on: August 30, 2014, 02:10:54 am »
Now, I'd like to work on other keys. Also I would not like to keep this part in the same place (it's uncomfortable for me) Should I do it like above (just adding else ifs, or with second event:

As I tried to explain above, you cannot do it with a second event loop.  That is not how pollEvent works.

The other point I tried to make is that after the pollEvent loop, you're free to do whatever you want, so it's not really a problem.  For instance, you could do this:
while(okno.open()) {
    ...
    std::queue<sf::Keyboard::Key> specialKeys;
    std::queue<sf::Keyboard::Key> normalKeys;
    sf::Event event;
    while (okno.pollEvent(event)) {
         if (event.type == sf::Event::Closed) {
            okno.close();
         } else if (event.type == sf::Event::KeyPressed) {
            if(event.key.code == sf::Keyboard::LAlt ||
               event.key.code == sf::Keyboard::RAlt ||
               ...) {
              specialKeys.push_back(event.key.code);
            } else {
              normalKeys.push_back(event.key.code);
            }
        } // other event types
    }

    // code to process specialKeys

    // code to process normalKeys

    // rendering and stuff
}
 

Now the only thing the pollEvent loop has to know about is your definition of a "special key".  Is this what you were trying to achieve?
« Last Edit: August 30, 2014, 02:13:17 am by Ixrec »

noct

  • Newbie
  • *
  • Posts: 24
    • View Profile
    • nctdev.pl
Re: [SFML 2.0]Problem with repeating buttons and events.
« Reply #16 on: August 30, 2014, 02:18:56 am »
@Ixrec: Get it now. It is, indeed, I haven't thought about splitting the queue like this.

Well, many things to read and try are waiting for me, but it's getting more and more interesting.  ::)
« Last Edit: August 30, 2014, 02:21:26 am by noct »