SFML community forums

Help => General => Topic started by: McMeatMan on December 09, 2011, 08:15:21 pm

Title: Avoid Repeating Input-Events
Post by: McMeatMan on December 09, 2011, 08:15:21 pm
Hi,

I have following problem in this Code:

Quote

      if(Window.GetInput().IsKeyDown(sf::Key::Down))
      {
         Sprite.Move(0,100 * ElapsedTime);
      }   



the sprite just shall go one time down, but if i write this into the code:

Quote

               while( Window.GetInput().IsKeyDown(sf::Key::Down) )


the Window crashes because of an infinity loop.

I hope you know the answear :)
Title: Avoid Repeating Input-Events
Post by: Tex Killer on December 09, 2011, 09:12:31 pm
The Input only gets updated when you pull for events.
You should make your loop pull for events, but that would cause your graphics to be frozen until you release the Down key. The best thing to do is move only 1 time per game frame.