I'm making my first applet game in Java, read a couple of tutorials and found different solutions for double-buffering. I would like to know what is the difference between them, any pros-cons, etc. Thanks in advance!
First one:
public void update(Graphics g) {
if (offImage == null) {
offImage = createImage(this.getWidth(), this.getHeight());
offGraphics = offImage.getGraphics();
}
offGraphics.setColor(getBackground());
offGraphics.fillRect(0, 0, getWidth(), getHeight());
offGraphics.setColor(getForeground());
paint(offGraphics);
g.drawImage(offImage, 0, 0, this);
}
Second one:
public void init() {
offImage = createImage(getWidth(), getHeight());
offGraphics = offImage.getGraphics();
}
public void paint(Graphics g) {
g.drawImage(offImage,0,0,this);
}
public void update(Graphics g) {
paint(g);
}