Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-09-2010, 12:30 PM
Member
 
Join Date: Feb 2010
Posts: 21
Rep Power: 0
martypapa is on a distinguished road
Default How do I improve the background image efficiency?
Hi,
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.

Thanks
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-09-2010, 09:23 PM
mrmatt1111's Avatar
Senior Member
 
Join Date: Aug 2009
Location: San Jose, CA, USA
Posts: 309
Rep Power: 2
mrmatt1111 is on a distinguished road
Default
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
__________________
My Hobby Project: LegacyClone
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-10-2010, 07:00 PM
Darryl.Burke's Avatar
Senior Member
 
Join Date: Sep 2008
Location: Madgaon, Goa, India
Posts: 1,047
Rep Power: 3
Darryl.Burke will become famous soon enough
Default
RXD, the question relates to Java2D, not to Java ME. Please read more carefully so that you don't again post a response which, while correct in its own way, is totally out of context.

db
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with JFrame background image ProGenius New To Java 6 12-27-2009 04:17 PM
Background image leiferouis New To Java 9 03-08-2009 05:49 PM
how i can put image in background of frame?? ahmed13 NetBeans 4 01-15-2009 05:47 PM
Image as background Java.child AWT / Swing 2 10-02-2008 11:37 PM
Background image in java toby AWT / Swing 1 07-29-2007 07:15 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:25 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org