1

I am working on a Java 2D video game, and developing it on Mac OS X 10.10.1. I am trying to do this all using the Java 2D api, and avoiding 3rd party libraries. I seem to be having display update issues, where sometimes things update very fast, then sometimes things seem to be sputtering along as if hesitant to update.

From reading other peoples comments with regard to Java 2D performance, I switched all my graphic images over to use of VolatileImage, and for any graphics that are not dynamic, I perform offscreen and copy to the screen invocation by invocation within my paintComponent routine (which is driven off a timer). And these images are created as VolatileImage as well.

I have noticed this jerky screen behavior after I made these performance enhancements (i.e. VolatileImages and offScreen drawing buffers). Now, the reason I made these changes is to take advantage of hardware acceleration. How can I check if this is occurring? And, any ideas on how to correct this jerky screen update issue I now have going on? I have seen people talk about use of dynamic timers, that would recalculate how long to wait for next update, given actual time spent on current update, to attempt to get smoothly updated graphic movements. Is this the way to do it? Or am I missing something?

Thanks.

user1104028
  • 381
  • 7
  • 18
  • Using a dynamic timer as you described will smooth the frame rate of your Java application. Without a more specific description of your game, there's not much else I can suggest. I wrote a [Spirograph simulation in Java Swing](http://java-articles.info/articles/?p=614) that plots hundreds of thousands of points in 5 milliseconds. – Gilbert Le Blanc Dec 26 '14 at 21:15

1 Answers1

0

You mention paintComponent, so I assume you are using Swing. Swing has double-buffering by default, you shouldn't add another layer of double-buffering. If you want to see how your Swing app behaves without the Swing double-buffering, add the -Dawt.nativeDoubleBuffering=true flag to the JVM arguments. Also note that double-buffering does not improve the frames-per-second performance, only the perceived performance, see this

Also see this: Java Hardware Acceleration

and this: Java : VolatileImage slower than BufferedImage

Community
  • 1
  • 1
lbalazscs
  • 17,474
  • 7
  • 42
  • 50