Ok so I was thinking about going to Jogl or Slick or LWGL but I’ve spent so much time with Java2d that I thought that maybe I could optimize things to run well on large screen sizes over 1000 wide. With that in mind, I’ve started testing everything I can think of. The first thing weird that occurs is the timer.
I’m using the standard Kevin Glass setup with a delta with non-recommended System.currentTimeMillis
try { Thread.sleep(loopTime+10-System.currentTimeMillis()); } catch (Exception e) {}
Results
- Framerate changes drastically everytime I run the test even though all I’m doing is drawing tiles and backgrounds. Sometimes it is 65 fps and others 94.
- For some reason setting the delay between 9-12 seems to have little effect on the frame rates.
Question: Why does the frame rate vary everytime I run it?
Okay so now I throw out the System.currentTimeMillis and go to the Gage timer.
try { Thread.sleep(loopTime+10-SystemTimer.getTime()); } catch (Exception e) {}
Presto I start getting 95 to 96 fps everytime.
Question why would I be getting a 1% improvement in frame rates wth a different timer?
Is there a better timer than Gage?
Additional notes: I reran these test about 60 times and it really seems like Java has an issue with the 10 delay. Even with both timers I get different frame rates. 11 is fine and 9 is fine but 10 seems to cause problems with both of them.