title: Object movement choppy when frame rate is capped
body: <p>I've been having some trouble with choppy movement of objects in a game.</p>
  
  <p>If the frame rate isn't capped, the game runs smooth.</p>
  
  <p>If I cap the frame rate at say, 60 fps, the movement is choppy.</p>
  
  <p>An object's movement looks like this...</p>
  
  <pre><code>m_distance += m_speed * GetFrameTime()
  </code></pre>
  
  <p>Where speed is in pixels per second, and GetFrameTime() returns the time elapsed since the last frame. Note that objects only move in x and y directions.</p>
  
  <p>I'm using SFML, with the functions <code>SetFramerateLimit(60)</code> and <code>UseVerticalSync(true)</code>. While trying to address the choppy movement issue, I read an article from an XNA developer about how they update once, render once, and then if there is time left in the game loop &lt; the frame rate (i.e. 1/60) then they'll sleep for the rest of that period. I believe this is what SFML does, because I disabled those functions and wrote in that behavior and I got the same symptoms.</p>
  
  <p>Now I'm not saying the above approach is a bad thing. In fact, I like that the application isn't doing needless work (there is a noticeable difference in resource usage when running the application with a set frame limit and without one). However, I really don't know why the movement is choppy. I've read the gafferongames articles but they don't seem to apply here.</p>
  
  <p>Any assistance is appreciated, thanks.</p>
  
  <p>Edit: I've identified the the issue, now just not sure how to solve it.</p>
  
  <p>On the frames where the object "jumps", the m_distance is significantly greater than distances in other frames. On closer inspection, the GetFrameTime() is also significantly greater than previous times between frames (significant is like 2-3 ms difference).</p>
  
  <p>Edit2: I believe I've come up with a solution thanks to <a href="http://gafferongames.com/game-physics/fix-your-timestep/" rel="nofollow">http://gafferongames.com/game-physics/fix-your-timestep/</a> . Set a fixed delta time instead of using GetFrameTime.</p>