Skip to content

Instantly share code, notes, and snippets.

@larsbutler
Forked from anonymous/GameCanvas.java
Created August 22, 2012 12:02
Show Gist options
  • Save larsbutler/3424862 to your computer and use it in GitHub Desktop.
Save larsbutler/3424862 to your computer and use it in GitHub Desktop.
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