I am trying to follow a tutorial on creating a game in Java but I am having trouble understanding the game loop.
I do not understand the purpose of this delta
variable.
Any help is appreciated.
public void run() {
long lastTime = System.nanoTime();
final double amountOfTicks = 60.0;
double ns = 1000000000 / amountOfTicks;
double delta = 0;
while(running) {
long now = System.nanoTime();
delta += (now - lastTime) /ns;
if(delta >= 1) {
tick();
delta --;
}
}
}