public
anonymous / GameCanvas.java
Created

Screen Tearing - GameCanvas.java

  • Download Gist
GameCanvas.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
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();
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.