added draw delay so it doesn't make my cpu scream

This commit is contained in:
Gavin McDonald
2016-02-24 22:06:56 -05:00
parent e78cedda18
commit 0e8d9019b5

View File

@@ -1,11 +1,14 @@
import {noop} from './utils.js';
export default class Sketch { export default class Sketch {
constructor(settings) { constructor(settings) {
this.lastNow = null; this.lastNow = null;
['getContext', 'onResize', 'render'].map(method => this[method] = this[method].bind(this)); ['getContext', 'onResize', 'render'].map(method => this[method] = this[method].bind(this));
this.draw = settings.draw || function() {}; // () => {}; this.drawDelay = settings.drawDelay || 50;
this.draw = settings.draw || noop;
this.container = settings.element || document.body; this.container = settings.element || document.body;
window.addEventListener('optimizedResize', this.onResize); window.addEventListener('optimizedResize', this.onResize);
@@ -34,7 +37,8 @@ export default class Sketch {
this.draw(this.context); this.draw(this.context);
this.lastNow = now; this.lastNow = now;
requestAnimationFrame(this.render);
setTimeout(() => {requestAnimationFrame(this.render)}, this.drawDelay);
} }
} }