javascript - reduce / thottle requestAnimationFrame for Canvas animation -
im creating html5 canvas animations , wish reduce / throttle frame rate. i'm using requestanimationframe method. throttle frame rate, use settimeout.
is there better / more efficient way this?
// game - animation loop var fps = 5; function step() { settimeout(function() { update(); draw(); window.requestanimationframe(step); }, 1000 / fps); }
thanks
const fps = 5; const delay = math.ceil(1000 / fps); let last = date.now(); let now; function step () { = date.now(); if(now - last < delay) { return requestanimationframe(step); } last = now; update(); draw(); requestanimationframe(step); } step();
Comments
Post a Comment