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

Author Topic: Delays in sprite movement  (Read 3032 times)

0 Members and 1 Guest are viewing this topic.

Nightspark

  • Newbie
  • *
  • Posts: 2
    • View Profile
Delays in sprite movement
« on: May 22, 2011, 01:08:57 am »
I got my program so I can move a sprite in all eight directions, or in a circle if I want, using the arrow keys. The problem occurs whenever I press a key, either to start moving or change direction. The character moves once, waits a half second or so, then moves steadily like I wanted. Any ideas what could be causing this delay/lag between movements? My input method is pretty standard.

//Located in event loop, same program structure in every SFML tut out there.

if (App.GetInput().IsKeyDown(sf::Key::Left))
       Player.SetSubRect(0, 0, 128, 128); //facing left
       Player.Move(-1, 0);

if (App.GetInput().IsKeyDown(sf::Key::Right))
       Player.SetSubRect( 128, 128, 256, 256); //facing right
       Player.Move(1, 0);

if (App.GetInput().IsKeyDown(sf::Key::Up))
       Player.Move(0, -1);

if (App.GetInput().IsKeyDown(sf::Key::Down))
       Player.Move(0, 1);

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Delays in sprite movement
« Reply #1 on: May 22, 2011, 01:39:45 am »
The problem is you have those if statements inside the events loop, have them outside of it and that should fix it
John Carmack can Divide by zer0.

Nightspark

  • Newbie
  • *
  • Posts: 2
    • View Profile
Thanks, but why is that?
« Reply #2 on: May 22, 2011, 11:53:25 pm »
Thank you, that fixed everything perfectly. Just curious though, why would putting those calls in the GetEvent() loop cause a delay?

 

anything