Hi,
I`ve a problem: I try to use double-buffering to avoid flickering, but this does not work; my code:
GraphicsDevice device =
GraphicsEnvironment
.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
GraphicsConfiguration gc = device.getDefaultConfiguration();
BufferCapabilities bufCap = gc.getBufferCapabilities();
boolean page = bufCap.isPageFlipping();
if (page) {
System.err.println("Page Flipping is supported!");
} else {
System.err.println("Page Flipping is not supported!");
}
DisplayMode newDisplayMode = new DisplayMode(640, 480, 16, 60);
try {
this.setUndecorated(true);
this.setIgnoreRepaint(true);
device.setFullScreenWindow(this);
this.requestFocus();
device.setDisplayMode(newDisplayMode);
try {
Thread.sleep(500);
} catch (Exception e) {
}
} catch (Exception e) {
e.printStackTrace();
}
this.createBufferStrategy(2);
this.strategy = this.getBufferStrategy();
bufCap = this.strategy.getCapabilities();
this.flipContents = bufCap.getFlipContents();
…
g = (Graphics2D) strategy.getDrawGraphics();
if (!flipContents.equals(BufferCapabilities.FlipContents.BACKGROUND)) {
// Clear background
g.setColor(Color.BLACK);
g.fillRect(0, 0, sizeX, sizeY);
}
//Draw the Map
this.map.render(g);
//Draw the player
this.sprite.render(g, 0, 0);
this.sprite.setX(spriteX);
this.sprite.setY(spriteY);
g.dispose();
strategy.show();
timer.sleepUntil(ticks+sleepTime);
Do you have a solution?
Thank you,
Sascha