Keeping your game at a consistent speed regardless of FPS

This was an issue I ran into when creating a pong clone. I use the SFML library with C++ to once in a while for some game programming. The problem is, if you have a set framerate, the object will be animated at each frame and will move the same distance in each frame. One needs to use time to modify the amount they move, so it's the same regardless of framerate. More specifically, the idea is get the elapsed time from when the last frame occurred, using the GetFrameTime() function of the SFML library.

With the time passed, you then use that as a multiplier to whatever value you were manipulating. So if you were initially moving the x position of a square by 10, you now call: x += (10 * app.GetFameTime());. That assumes that your sf::RenderWindow object is named app. What this does is modifies the 10 appropriately so the square moves the same distance regardless of FPS. This is fairly important, especially for a multiplayer game. So players with legacy computer parts arent slower than the players with cutting edge video cards.

Here is a much more in-depth read of this topic: Fix your timestep. If you want to learn how to use SFML for 2d game development, the main website is a great resource for tutorials http://www.sfml-dev.org/tutorials/1.5/.

This was an issue I ran into when creating a pong clone. I use the SFML library with C++ to once in a while for some game programming. The problem is, if you have a set framerate, the object will be animated at each frame and will move the same distance in each frame. One needs to use time to modify the amount they move, so it's the same regardless of framerate. More specifically, the idea is get the elapsed time from when the last frame occurred, using the GetFrameTime() function of the SFML library.

With the time passed, you then use that as a multiplier to whatever value you were manipulating. So if you were initially moving the x position of a square by 10, you now call: x += (10 * app.GetFameTime());. That assumes that your sf::RenderWindow object is named app. What this does is modifies the 10 appropriately so the square moves the same distance regardless of FPS. This is fairly important, especially for a multiplayer game. So players with legacy computer parts arent slower than the players with cutting edge video cards.

Here is a much more in-depth read of this topic: Fix your timestep. If you want to learn how to use SFML for 2d game development, the main website is a great resource for tutorials http://www.sfml-dev.org/tutorials/1.5/.