I had problems with the volatile movement of objects in the game.
If the frame rate is not limited, the game runs smoothly.
If I limit the frame rate to, say, 60 frames per second, the movement will be intermittent.
The movement of the object looks like this:
m_distance += m_speed * GetFrameTime()
Where is the speed in pixels per second, and the GetFrameTime () function returns the time elapsed since the last frame. Note that objects only move in the x and y directions.
I am using SFML with SetFramerateLimit(60)and functions UseVerticalSync(true). Trying to solve the problem of intermittent movement, I read an article from the XNA developer about how they are updated once, then once, and then, if there is time left in the game loop, the frame rate (i.e. 1/60), then they will be sleep until the end of this period. I believe this is what SFML does, because I disabled these functions and wrote in this behavior, and I got the same symptoms.
Now I'm not saying that the above approach is bad. In fact, I like that the application does not do unnecessary work (there is a noticeable difference in the use of resources when launching the application with the set frame limit and without it). However, I really don't know why the movement is volatile. I read gafferongames articles, but they don't seem to apply here.
, .
: , , .
, "", m_distance . GetFrameTime() , ( 2-3 ).
Edit2: , http://gafferongames.com/game-physics/fix-your-timestep/. - GetFrameTime.