Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java graphics performance

Tags:

java

graphics

I was programming a simple game and wanted to display it via the Java Graphics + Swing API. It felt a little slow, of course, so I measured how long it took to repaint, which was around 32ms. Then I read about accelerated Java graphics and used the method described here: Space Invaders

However, somehow this is even slower. It now takes around 98ms to redraw. Why is that?

Note that I am aware of libraries like LWGL and JOGL, but I don't want to use a full-blown OpenGL wrapper for such a graphically simple game.

like image 937
Marc Müller Avatar asked Dec 12 '09 13:12

Marc Müller


1 Answers

A few hints to improve performance:

  1. Clip and just draw the area that has changed
  2. Don't scale anything when drawing
  3. Use the correct buffer strategy
  4. Use full screen exclusive mode if appropriate.

Swing isn't inherently slow. Most of the confusion about Swing comes from people who don't know or understand about the Event Dispatch Thread (and yes, it's a lot of effort to get it right).

Regarding your times, are you just calling g.drawImage between the time settings? If so, what size are you repainting, and are you doing any scaling on this call?

EDIT: Forgot to mention Pulp Core - a very nice gaming framework for Java.

like image 132
Pool Avatar answered Oct 31 '22 12:10

Pool