Hi Guys,
I am actually trying to understand the timestamp value calculation in the below code snippet (this is actually a paddle moving from left to right and the code is working all fine)
But i am still a bit confused with the return value it produces , like in the below code…
function gameLoop(timestamp){
let deltaTime=timestamp- lastTime;
lastTime = timestamp;
ctx.clearRect(0,0,800,600);
// the update function will recalculate the x and y coordinate from where the new paddle will appear
paddle1.update(deltaTime);
// the draw method will redraw the paddle with new x,y coordinates
paddle1.draw(ctx);
requestAnimationFrame(gameLoop);
}
gameLoop();
so, the thing i am confused about is,
1- when the gameloop() fuction is called first, it will go through the gamLoop function with no parameter?, so will timestamp will be zero initially?
2- also how come requestAnimationFrame(gameLoop); will return a timestamp value (that will then be used by gameloop each time it get looped)?
really appreciate your help
Thanks
Umair