I\'m writing an HTML5 Game Development Javascript framework and I want to provide the user the difference in time between the last tick and the current one.
Would like to give my two cents. Usually I use this deltatime method in my games:
const perfectFrameTime = 1000 / 60;
let deltaTime = 0;
let lastTimestamp = 0;
function start() {
requestAnimationFrame(update);
}
function update(timestamp) {
requestAnimationFrame(update);
deltaTime = (timestamp - lastTimestamp) / perfectFrameTime;
lastTimestamp = timestamp;
// YOUR FRAME CODE HERE!
}
start();
This ensure you will have perfect deltatime (as like Unity deltaTime) so you can scale your times to frame time.