Skip to content
Create a gist now

Instantly share code, notes, and snippets.

anonymous /

More sophisticated double-buffered rendering
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);
} while (strategy.contentsRestored());;
} while (strategy.contentsLost());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.