The Source for Java Technology Collaboration


Rendering 2D Games in Java

There is no "best" way to approach rendering 2D games in Java, there are a few options with different pros and cons.

Java 2D Direct

Java2D allows the creation of graphics contexts that can be drawn to directly. For instance, overriding Frame.paint(Graphics g) and using the Graphics object to draw onto the screen will of course let you write a 2D game. Its very simple to use, but its also very slow - and whats more due to the way the refresh happens the update of hte screen isn't consistent. This method is only really good for static screen games.

Java 2D With Buffered Strategy

Java2D also provides the ability to use hardware accelerated buffer to perform the rendering. The BufferStrategy class provides this functionality as a simple API. This method is considerably faster than using the direct painting method, however it is part of JDK and hence you don't need to distribute any native librarys or extension libraries.

OpenGL

OpenGL can be accessed via JOGL or LWJGL. Rendering 2D graphics in OpenGL is very fast and utilises hardware where possible. However, this does mean distributing native libraries with your game.

Most Java 2D developers eventually turn to OpenGL rendering for performance reasons.

-- Main.kevglass - 24 Oct 2005

Topic Rendering2D . { Edit | Ref-By | Printable | Diffs r1 | More }
 XML java.net RSS

Revision r1 - 24 Oct 2005 - 17:42:19 - Main.kevglass
Parents: WebHome > FAQ