Create a gist now

Instantly share code, notes, and snippets.

anonymous /GameCanvas.java
Created Aug 18, 2012

Screen Tearing - GameCanvas.java
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferStrategy;
public class GameCanvas extends Canvas {
private BufferStrategy strategy;
public GameCanvas() {
setVisible(true);
}
public void initBufferStrat() {
createBufferStrategy(2);
strategy = getBufferStrategy();
}
public void render() {
Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
// Draw the background:
g.setColor(Color.black);
g.fillRect(
0, 0,
GameWindow.SIZE.width,
GameWindow.SIZE.height);
// Draw player:
g.setColor(Color.orange);
g.fillRect(GameKernel.playerX, GameKernel.playerY, 48, 96);
g.dispose();
strategy.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment