Regarding Frame Rate

I’ve really been looking into frame rate in my games for some time, and now its really bugging me. I’ve been doing many different methods of keeping frame rate, and I can’t find a single one that is effective and precise. This is the one I’m using right now:

http://pastie.org/private/vows8sgvcrkeuixsgvj3g

I’ve also noticed that when entities disappear from the screen(they’re still being updated and rendered, just not visible to you), the consistency of the frame rate starts improving.

So, I’m looking for a few things here:

  1. What is the best way to handle frame rate?
  2. A good way to handle and store entities. I use an ArrayList and I just loop through them two times to render and update.

Its been really bugging me for awhile, especially when there are about 50 entities on the screen.

Please help D:

That’s lag. You are taking to long to draw things sometimes. Changing the game loop won’t help.

For calculating framerate and running a gameloop, this is what I use. Works wonders for me. It was written for Java2D, which I’m assuming you’re using due to your problem-description.

Hope it helps.

And if your entities are still being updated and rendered when they’re not visible, you should probably do something about that. I don’t do a draw-call on entities that are not on the screen, and if they’re more than 200px outside the screen, I don’t even run update(deltaTime) on them. Saves a lot in a big world.

You might consider making the game loop a util.Timer. You can specify the exact repeating time interval as a parameter. But if you take too long to render, the timing will be thrown, just as it is in a game loop.

Some folks don’t like Timers, and the swing.Timer is very problematic as the EDT gets clogged up pretty quickly. But “Killer Game Programming” seems to demonstrate that a util.Timer is a reasonable option, even if it isn’t their first choice. I don’t know why more people don’t use them. Fear of multithreading? That seems misplaced to me, since a new thread isn’t launched until the previous one completes.