I was working on my game, adding stuff to it, when I noticed my ticks were in the low 50's when I had set it to do a constant 60. This is my run method.
public void run() {
init();
long lastTime = System.nanoTime();
final double amountOfTicks = 60.0;
double ns = 1000000000.0 / amountOfTicks;
double delta = 0;
int updates = 0;
int frames = 0;
long timer = System.currentTimeMillis();
while (running){
long now = System.nanoTime();
delta += (now - lastTime) / ns;
lastTime = now;
if (delta >= 1) {
gameUpdate();
updates++;
delta--;
}
try {
Thread.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
gameRender();
frames++;
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
frame.setTitle(title + " | " + "Frames Per Second: "
+ frames);
System.out.println(updates + " Ticks, " + frames + " Frames");
updates = 0;
frames = 0;
}
}
stopGame();
}
I've tried removing all the code I added before this occurrence happened and it didn't help. Suggestions would be great!