public
anonymous / DB.java
Created

More sophisticated double-buffered rendering

  • Download Gist
DB.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
private VolatileImage drawImage = null;
private int drawImageWidth = 800;
private int drawImageHeight = 600;
 
public void render(BufferStrategy strategy) {
if (drawImage == null) {
drawImage = createVolatileImage(drawImageWidth, drawImageHeight);
}
Graphics2D drawGraphics = (Graphics2D) drawImage.getGraphics();
// TODO: use `drawGraphics` to draw game graphics (background, platforms, player, etc.)
 
// render a single frame:
do {
do {
Graphics2D renderGraphics = (Graphics2D) strategy.getDrawGraphics();
renderGraphics.drawImage(drawImage, 0, 0, null);
renderGraphics.dispose();
} while (strategy.contentsRestored());
strategy.show();
} while (strategy.contentsLost());
Toolkit.getDefaultToolkit().sync();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.