Skip to content

anonymous /GameKernel.java

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Screen Tearing - GameKernel.java
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.