Hi,
In my main game loop, I am using this simple method to count the number of frames:
long startTime = System.currentTimeMillis();
fireShots();
updatePosition();
manageFighter();
checkForGameEnd();
manageEnemies();
render();
usedTime = System.currentTimeMillis() - startTime;
where the functions are pretty self-explaining for a 2d shooter game. They contain all the world logic and render() just calls the repaint() method from my graphical interface.
The problem is that I keep getting extremely low usedTime’s, +/- 1 msec. The problem is that it seems that a call to repaint() is pretty fast and that it doesn’t take into account the actual time to do the paint().
So would you suggest to set usedTime() at the end of the paint() or is there a better way ?
Update:
I tried to move the usedTime calculation at the end of the paint() function and am getting better results. My framerate is now around 40 fps which seems ok. But I keep getting an odd problem:
I am using a thread with a timeout of 40 to run the main game loop and as described in the Java2D forum, I am trying to blur the foreground BufferedImage on the fly to make it look better.
This gives me a very rough animation and the smoothness of the animation (which I get without using the BLUR) is gone.
But my framecounter keeps telling me that I have 50 FPS which is impossible when I look at the actual result ?!