i'm a beginner at java. I'm trying to learn game developing. I'm watching the tutorials of this great programmer on youtube! I'm following him exactly and reached up to "#9 - Basic Collision Bounds" of this playlist.
He created the following game loop...
public void run(){
init();
long lastTime = System.nanoTime();
final double amountOfTicks = 60.0;
double ns = 1000000000 / 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){
tick();
updates++;
delta--;
}
render();
frames++;
if(System.currentTimeMillis() - timer > 1000){
timer += 1000;
System.out.println(updates + " Ticks, Fps " + frames);
updates = 0;
frames = 0;
}
}
stop();
}
I'm very confused about this method. How is this method functioning? How the following variables are working?
amountOfTicks
delta
updates
frame
I understand explaining this here is not very feasible but please help me. You can also give me any reference to study and understand this. If you need any further information, i'll provide it straight away!