anonymous / GameKernel.java
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Screen Tearing - GameKernel.java

View GameKernel.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 38 39 40 41 42 43
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.Timer;
 
 
public class GameKernel implements Runnable {
 
public static int playerX = 400;
public static int playerY = 300;
private int moveVel = 10;
private int direction = 1;
 
private Timer timer;
public static final int TIMESTEP_MS = 10;
public void run() {
final GameWindow gw = new GameWindow();
 
ActionListener taskPerformer = new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
update();
gw.render();
}
};
timer = new Timer(TIMESTEP_MS, taskPerformer);
timer.start();
}
 
public void update() {
playerX += direction * moveVel;
if (playerX >= GameWindow.SIZE.width - 100) {
direction *= -1;
}
else if (playerX <= 100) {
direction *= -1;
}
}
 
}
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.