Hi, i've recently tried to move sprite in my Pong game, and it basically works but when i press key it moves one tick, and if i keep the key pressed it starts to move normally. Using sfml 2.1 and events and some booleans flags, something like this:
bool holdingLeft;
while(window.pollEvent(event))
{
switch(event.type)
{
case sf::Event::KeyPressed:
handlePlayerInput (event.key.code, true);
break;
}
}
void handlePlayerInput(sf::Keyboard::Key key, bool isPressed)
{
if (key == sf::Keyboard::Left)
holdingLeft = isPressed;
}
sf::Vector2f movement(0.f, 0.f);
if (holdingLeft)
movement.x -= 10.0f;
sprPlayer.move(movement);
My question is why is this happening and how to make it run smoothly?
PS. I noticed that when i move the mouse over the window in the same time it is bit better. It seems like window isn't focused and rendering whole time and when u move mouse over it runs smoother. ( I haven't done anything connected with mouse in code )