
May 17th, 2009, 12:37 PM
|
|
|
Quote: | I want to control the FPS so I can get a constant 60 FPS. How can I do this? | Let me guess, ultimately you have a loop that looks like: while { updateGame() }. And you've discovered that such a naive loop mechanism has the following consequence. The game speed is tied to the computer speed. With no upper bound.
There's no one way, correct way, easy way, or quick way, or whatever to deal with this. You should prepare to do some reading about this topic. A good google term is "timestep" or "time step". Combined that with other related terms like "game" and "fps" and you should get some good articles. Also google for "fix your timestep" which is an article. Some of these articles don't seem relevant, like the fix your timestep article because it very much concerns itself with physics. But spend the time reading it and other articles.
You should eventually pick up on two ideas. The first is that you update the game only every so often. So if your game is clocked to 60 FPS, how many seconds elapse before an update? Or, you update the game as fast as possible. But you scale the updates to match the update speed. Let's say an object is moving at 1 meter/sec at 60 FPS. Your game runs at 100 FPS instead. How much distance should it being per frame in the 100FPS case?
__________________
When you ask a question, be prepared to tell us: what have you tried? If you think you don't need to try anything, we will never be interested in helping you. If you agree with the link, and you refuse to answer that question, you are being a hypocrite.
Need help with broken code? Your question should be like a good bug report: (1) It has the smallest number of steps to reproduce the problem you see (2) It tells us precisely what you expected to see and (3) It tells us what you saw and how it differed from what you expected. We need all three to help you.
Want better answers? Tell us what you Googled for and what steps you took to answer your own question.
|