I am writing Pong using SFML and am having a small problem with the input. When I press "W" which makes the paddle go up, it goes up 10 pixels then delays for like half a second and then goes up smoothly. If possible I would like to get rid of the delay. Below is the code that is causing this problem:
while(win.IsOpened( ))
{
while(win.GetEvent(event))
{
switch(event.Type)
{
case (sf::Event::Closed):
win.Close();
break;
//---------- W ----------
case (event.KeyPressed):
if(event.Key.Code == sf::Key::W)
{
//move paddle up
}
//---------- S ----------
if(event.Key.Code == sf::Key::S)
{
//move paddle down
}
break;
}
}
I am trying to change that to something like the code below to make the movement more smooth when a key is held down. The only problem is this does not work. Can anyone point me in the right direction?
You have the right idea with setting your 'w' and 's' variables to true/false.
All you have to do after that is move the paddle based on the state of those vars. You should check them once per frame -- the same time you move the ball and do other game logic.