我正在用 Java 制作我的第一个小程序游戏,阅读了一些教程并找到了不同的双缓冲解决方案。我想知道它们之间有什么区别,任何利弊等。在此先感谢!
第一:
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);
}
第二个:
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);
}