解决Frame闪烁问题(双缓冲)
程序员文章站
2022-06-10 10:48:29
...
与paint方法同级,加上这段代码就OK了
private Image offScreenImage = null;
public void update(Graphics g) {
if(offScreenImage == null) {
//这是游戏窗口的宽度和高度
offScreenImage = this.createImage(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
}
Graphics gOff = offScreenImage.getGraphics();
paint(gOff);
g.drawImage(offScreenImage, 0, 0, null);
}