I’ve written a simple app which shows some graphics on the screen and does some very basic sprite movement. I don’t know/understand the best way to redraw each frame though.
What I’m doing now is approximately this -
paintComponent(Graphics g) {
// fill my bufferedimage with black
// Draw some stuff directly on the g context
// pass the graphics context of my bufferedImage to a routine
// do a drawImage call on g with my bufferedImage
}
This works, but it seems like a very ‘expensive way’ to do the drawing each frame. Is there some way to clear out the bufferedImage without doing a fill? Would it be better to create a new image each time - seems like I’d be moving lots of memory around that way.
I read the article at -
http://weblogs.java.net/pub/wlg/435
and wondered if using a volatile image would be a better way. I’m not using full screen mode. I’m drawing on a JPanel, by overriding its paintComponent method.
Thanks!