# Controlling FPS in my game?

This topic is 3893 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

How can I control FPS in my game? I have a pong game going under OpenGL, C++ and the paddles move the way I want them on my PC, but on my school's pcs. They move very fast! So how can I keep that from happening? I did look for code samples and articles, but couldn't find any. :(

##### Share on other sites
Quote:
 Original post by ajm113How can I control FPS in my game? I have a pong game going under OpenGL, C++ and the paddles move the way I want them on my PC, but on my school's pcs. They move very fast! So how can I keep that from happening? I did look for code samples and articles, but couldn't find any. :(

##### Share on other sites
Sorry I thought I clicked on the Game Dev forums, but oh well. Oh yeah I need to add a time of milliseconds that I render my game correct?

##### Share on other sites
Quote:
 Original post by ajm113How can I control FPS in my game? I have a pong game going under OpenGL, C++ and the paddles move the way I want them on my PC, but on my school's pcs. They move very fast! So how can I keep that from happening? I did look for code samples and articles, but couldn't find any. :(

The technique you're describing is generally called a "frame limiter", and is mostly no longer used (except maybe when the hardware configuration is fixed).

Instead, you should try to implement "frame-rate independent movement", so that no matter what the frame-rate is, the game will play at the same speed.
This is achieved by measuring the length of time that it takes your game to process a single frame, and multiplying all speed values by this elapsed-time value.

For example, this hypothetical game loop updates a position value by a fixed amount:
while( shouldQuit == false ){  if( keys['A'] == true )    position += 1;  if( keys['Z'] == true )    position -= 1;  UpdateOtherStuff();  Render();}

This one updates by a variable amount depending on the frame-rate:
float currentTime = getTimeInSeconds();float lastTime = currentTime;float deltaTime;while( shouldQuit == false ){  deltaTime = lastTime - currentTime;  lastTime = currentTime;  currentTime = getTimeInSeconds();  if( keys['A'] == true )    position += 1.0f * deltaTime;  if( keys['Z'] == true )    position -= 1.0f * deltaTime;  UpdateOtherStuff( deltaTime );  Render();}

These examples are based off a hypothetical "getTimeInSeconds" function - the easiest way to make one of these is to use the timeGetTime on Windows.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633328
• Total Posts
3011375
• ### Who's Online (See full list)

There are no registered users currently online

×