Setting up the Animation Timer

The render and onFrame functions look exactly the same as in the previous examples:

function onFrame() {
elapsedTime = (new Date).getTime() - initialTime;
if (elapsedTime < animationRate) return;

let steps = Math.floor(elapsedTime / animationRate);
while (steps > 0) {
animate();
steps -= 1;
}

initialTime = (new Date).getTime();
}

function render() {
initialTime = (new Date).getTime();
setInterval(onFrame, animationRate / 1000);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.135.63