Results 1 to 3 of 3
- 02-09-2010, 01:30 PM #1Member
- Join Date
- Feb 2010
- Rep Power
How do I improve the background image efficiency?
I am making a game that uses a thread to animate. When I repaint a large percentage of my CPU is taken up. I am assuming this has something to do with the large background image.
Firstly, is it better to use an Image or Buffered Image for the background in this case, keeping in mind that there are buttons and shapes overlapping it that get repainted regularly.
If there is no difference, would it help to draw the background onto a different graphics context, if that is possible and makes any sense.
- 02-09-2010, 10:23 PM #2Java Code:
BufferedImage backimage = ((Graphics2D)this.getGraphics()).getDeviceConfiguration().createCompatibleImage( width, height,java.awt.Transparency.OPAQUE);
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 screenMy Hobby Project: LegacyClone
- 02-10-2010, 08:00 PM #3
- By ProGenius in forum New To JavaReplies: 6Last Post: 12-27-2009, 05:17 PM
- By leiferouis in forum New To JavaReplies: 9Last Post: 03-08-2009, 06:49 PM
- By ahmed13 in forum NetBeansReplies: 4Last Post: 01-15-2009, 06:47 PM
- By Java.child in forum AWT / SwingReplies: 2Last Post: 10-02-2008, 11:37 PM
- By toby in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 07:15 AM