SFML community forums
Help => Window => Topic started by: pentex 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
-
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.
-
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:
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
-
You check inputs only when an event occurs, so you end up with the same problem. Use sf::Input outside your event loop.
-
Ahh yes, it works now, thanks very much :)