Skip to content

Add simple rate-limiting to requestAnimationFrame #18

@pirate

Description

@pirate

Add a simple rate-limit to requestAnimationFrame to make sure even if tick() gets called multiple times, it'll only ever run once per frame:

function redraw() {
  drawPending = false;
  // Do drawing ...
}

var drawPending = false;
function requestRedraw() {
  if (!drawPending) {
    drawPending = true;
    requestAnimationFrame(redraw);
  }
}

https://developer.mozilla.org/en-US/docs/Games/Techniques/Efficient_animation_for_web_games

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions