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

Author Topic: Delayed input when key is held down  (Read 5524 times)

0 Members and 3 Guests are viewing this topic.

pentex

  • Newbie
  • *
  • Posts: 7
    • View Profile
Delayed input when key is held down
« on: November 29, 2010, 10:47:15 pm »
Hi, I'm writing a game atm using SFML and I want WSAD to be the movement keys. The problem is that when they are held down to move forwards/backwards etc there is a delay. The player initially moves one iteration forward and then pauses momentarily before the repeated input kicks in and he starts moving forward smoothly. Is there a way to turn this delay off? Or some other solution? I'm used to using XNA where there isn't a delay of this sort.

Thanks!
Stephen

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Delayed input when key is held down
« Reply #1 on: November 29, 2010, 10:52:31 pm »
This is because you react on key press events, whereas you should move your character as long as the key is held down.

See sf::Input (tutorial and doc) for the solution to your problem.
Laurent Gomila - SFML developer

pentex

  • Newbie
  • *
  • Posts: 7
    • View Profile
Delayed input when key is held down
« Reply #2 on: November 29, 2010, 11:22:58 pm »
Thanks for the quick response. I'm already using sf::input though, I initially checked the documentation and switched from checking window events to using sf::input, but for some reason it still behaves the same way. Here's the code:

Code: [Select]
void ProcessKeyboard(sf::Event Event)
{
const sf::Input& input = window.GetInput();
if (input.IsKeyDown(sf::Key::Escape))
window.Close();

        //old code
//if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code   == sf::Key::W))
//{

// new code
if (input.IsKeyDown(sf::Key::W))
{

Am I missing something?
Thanks,
Stephen

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Delayed input when key is held down
« Reply #3 on: November 29, 2010, 11:30:13 pm »
You check inputs only when an event occurs, so you end up with the same problem. Use sf::Input outside your event loop.
Laurent Gomila - SFML developer

pentex

  • Newbie
  • *
  • Posts: 7
    • View Profile
Delayed input when key is held down
« Reply #4 on: November 29, 2010, 11:44:02 pm »
Ahh yes, it works now, thanks very much :)