Need some clarification vs repaint() and buffered images

Ok, ive seen various source codes that use either repaint(), or games (IE Kev Glass’s Space Invaders) that uses this “buffered grafhics” and it is very different that a diferent way I’ve been learning it. So I assume you need to use the buffer strategy to use accelerated graphics, and repaint() is just a thing used for applets, or stand alone canvas if you want, like ive been doing. So what is really the difference between using the repaint() and the buffer.

Thank you for the help.

repaint() is mostly used in passive rendering, while buffer (drawing yourself) in active rendering … search forums, there are many topics about it

well the main point with using repaint() instead of doing that yourself is that you cant control the time on when it happens when you are using repaint(), because it is actually not a demand to repaint, but a request. When you are making games, you want to control it yourself, because you want the painting to be done at accurate times, else the time between 2 redraws is different every time and you will see ‘tearing’ or flickering.

depends on a game… repaint() works fine with table type games or other games where display changes primarly on user interaction

That’s right, but tearing/flickering are unrelated problems. Using repaint() vs BufferStrategy.show() or some other method just comes down to timing - active vs passive rendering. Passive rendering is OK for board games since they’re not real-time, they’re turn-based. Animations really need to be actively-rendered - ie not queued on the event dispatch thread but done straight away in your own game loop thread.

Tearing is caused by not v-syncing with the monitor refresh. You can’t avoid tearing unless in full screen mode.

Flickering is from not ‘double-buffering’. Swing is double-buffered by default so repaint() won’t cause flicker. BufferStrategy’s with more than one buffer also won’t flicker.

Hope that helps :),
Keith

okay didnt knew, nice to know tho, thanks :slight_smile: