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.