Skip to content

Commit

Permalink
Use requestanimationframe for better performance and grouping functio…
Browse files Browse the repository at this point in the history
…ncalls
  • Loading branch information
Filip Smets committed Feb 2, 2016
1 parent e4af593 commit 5677c94
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions TiledCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ TiledCanvas.prototype.normalizeDefaults = function normalizeDefaults (target, de
// will actually be executed
TiledCanvas.prototype.redrawOnce = function redrawOnce () {
if (!this._redrawTimeout)
this._redrawTimeout = setTimeout(this.redraw.bind(this));
this._redrawTimeout = requestAnimationFrame(this.redraw.bind(this, false));
};

TiledCanvas.prototype.redraw = function redraw (noclear) {
clearTimeout(this._redrawTimeout);
cancelAnimationFrame(this._redrawTimeout);
delete this._redrawTimeout;

if (!noclear) this.ctx.clearRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
Expand Down

0 comments on commit 5677c94

Please sign in to comment.