So I’ve been using the game loop below for most of the games I’ve made and as I was just going through it I found there is one part I’m having trouble
trying to understand, specifically the line just below.
delta += (now - lastTime) / nanos;
I understand we are finding the time difference and adding it to the delta variable but I don’t understand why we are then dividing it by the nanos variable (1000000000 / 60). I pasted the full game loop below.
long lastTime = System.nanoTime();
final double nanos = 1000000000.0 / 60.0;
double delta = 0;
int frames = 0;
int updates = 0;
requestFocus();
while(running){
long now = System.nanoTime();
delta += (now - lastTime) / nanos;
lastTime = now;
while(delta >= 1){
gameUpdate();
delta--;
}
render();
}
}
}
If anyone could help me by explaining whats happening on the line I pointed out, it would be very appreciated. Thanks!