Skip to content

Instantly share code, notes, and snippets.

Created August 18, 2012 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/3389138 to your computer and use it in GitHub Desktop.
Save anonymous/3389138 to your computer and use it in GitHub Desktop.
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