views:

146

answers:

1

Quick Java graphics question. From all the graphics tutorials I've seen it looks like using Graphics2D the entire canvas is repainted. I'm trying to make a game and I'm wondering if there's a way to only paint the parts of the canvas that are to be updated on a certain cycle. Do you guys know if this is possible / necessary?

+1  A: 

You can use repaint(x,y,w,h) to cause only a portion of the component to be updated. But afaik most java games implement some kind of offscreen painting (i.e. they render the complete scene into a bitmap) and flip this entire bitmap to the screen periodically.

The problem with the standard Swing repaint mechanism is that you have no means to exactly control when the new frame is painted (repaint causes the control to be repainted 'as soon as possible'...)

You might want to look at

for further information/ideas on java game development.

MartinStettner
+1 excatly what I was about
stacker