Reputation: 350
How can I calculate the elapsed time the render function needs to execute once? I would like to use this time for other functions later. Currently I just receive time_ elapsed = 0 .
function render() {
window.requestAnimFrame(render, canvas);
time_start.getTime();
// do rendering
scene.render(); //here are my draw calls
time_end.getTime();
time_ elapsed = time_end - time_start;
console.log(time_ elapsed);
}
Upvotes: 1
Views: 209
Reputation:
Here's a typical way to do it.
function currentTimeInSeconds() {
return Date.now() * 0.001;
}
var then = currentTimeInSeconds() {
function render() {
var now = currentTimeInSeconds();
var elapsedTimeInSeconds = now - then;
then = now;
scene.render();
requestAnimationFrame(render);
}
render();
Upvotes: 1