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

Author Topic: [solved]key events in 2.0  (Read 2232 times)

0 Members and 1 Guest are viewing this topic.

Khnemu

  • Newbie
  • *
  • Posts: 11
    • View Profile
[solved]key events in 2.0
« on: October 31, 2012, 06:58:13 pm »
Hi !
I'm testing out sfml 2.0 on windows (visual studio 2010).
I just switched between polling the keyboard in real time to using events 5even though the result should be the same).
So here's basically what i do now:
  while (isRunning)
    {
      Window.clear(sf::Color(88, 148, 88));

      while (Window.pollEvent(Event))
      {
          switch(Event.type)
                {
                 case sf::Event::Closed:
             isRunning = false;
             break;

                case sf::Event::KeyPressed:
                        player->injectKeyPressed(Event.key.code);
                        break;

            case sf::Event::KeyReleased:
                  player->injectKeyReleased(Event.key.code);
              break;
                }
      }
 
Inside the keypress/released functions of my player object, i just set a boolean value in a map to reflect this.
Here's a code sample:
bool Player::injectKeyPressed(sf::Keyboard::Key key)
{
        keyboardState[keyboardMap[key]] = true;

        return true;
}
 
However, since i changed it, i've been having bugs (up key isn't working properly when it was before and the other keys share the same code).

So is this incorrect behavior ? Or is it just not a good idea in sfml ? Because i've used this kind of keyboard input events in other libs and never had any problem.
« Last Edit: October 31, 2012, 07:44:46 pm by Khnemu »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: key events in 2.0
« Reply #1 on: October 31, 2012, 07:10:32 pm »
Your code looks good.

What does keyboardMap does?

Could you provide a complete and minimal code that reproduces the problem?
Laurent Gomila - SFML developer

Khnemu

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: key events in 2.0
« Reply #2 on: October 31, 2012, 07:27:40 pm »
edit:

Bah...found the problem, had nothing to do with sfml.
Sorry for the trouble heh x) i actually accidentally removed something in the code for some reason ~
« Last Edit: October 31, 2012, 07:44:31 pm by Khnemu »

 

anything