|
Code:
|
BufferedImage backimage = ((Graphics2D)this.getGraphics()).getDeviceConfiguration().createCompatibleImage(
width, height,java.awt.Transparency.OPAQUE); |
What i do is render to a backimage but only when things change.
I have a background scenery with ground tiles (many of them), roads, trees that for most of the time don't update. If the user moves the scene then i re-render this part to the backimage.
For those things that do change constantly, like animations, i draw them to the graphics object everytime the panel is painted (paintComponent).
Flow for paintComponent:
- Did the scene move (they moved it with the mouse)?
yes - redraw all the non animated images to
backimage
no - leave backimage alone
- draw the
backimage to the screen
- draw all the animated images to the screen