#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2008
    Posts
    4
    Rep Power
    0

    How to control FPS


    I'm working on an Invaders-like game, the problem is I cannot work with the speed of the actors. I have to switch between two computers, a new one and an old one, so in the new one, everything (ie bullets and enemies) moves very quickly (FPS counter shows 200 FPS), while on the old computer, everything moves very slowly (FPS counter shows 60).

    I want to control the FPS so I can get a constant 60 FPS. How can I do this?

    Edit: I'm programming in Java.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 2006
    Posts
    2,270
    Rep Power
    1737
    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.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    21
    Rep Power
    0
    Originally Posted by Oler1s
    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?
    I agree.

    And I'll add the following: the scaling option an advantage. If you should run the program on a very slow machine (so you can't get your target frame rate), then you can still move the correct distance per second.

IMN logo majestic logo threadwatch logo seochat tools logo