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:
public class EmptyGame
{ 
   public static void main( String[] args ) 
   { 
     EmptyGame test = new EmptyGame(); 
   } 
  // A delay of 20L should give us 50 fps (1000 / 20)
  private static final long DELAY = 20L; // try either 19L or 21L to see the difference
  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) {}
      // Un-comment the following line to see the actual delay
      //System.out.print(System.currentTimeMillis()- startTime+"  ");
    } 
  } 
}
Please try it out and see for yourself. Is there something that I’m not aware of? Another Java bug perhaps?
Thanks.
 
      
    