Ok here's the thing. I was testing my game at 50 frames per second. As you know the delay for 50 fps is 20 ms. I tried it out and all I could get was 32 fps.
I thought it was my game, so I stripped it out of "suspicious" methods and classes, but nothing. I ended up making a little program to test this fps situation.
The result was to say the least crazy. 20ms delay produces in reality a 31 or 32 ms delay. 19ms or 21ms (or anything else) delays are almost okay. Check out the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public class EmptyGame { public static void main( String[] args ) { EmptyGame test = new EmptyGame(); }
private static final long DELAY = 20L; public EmptyGame() { long startTime; int frames = 0; long fpsTime = System.currentTimeMillis();
while( true ) { startTime = System.currentTimeMillis(); frames++; if (startTime - fpsTime > 999) { System.out.println("FPS: " + frames); frames = 0; fpsTime = startTime; } try { Thread.sleep( DELAY ); } catch(Exception e) {}
} } } |
Please try it out and see for yourself. Is there something that I'm not aware of? Another Java bug perhaps?
Thanks.