Skip to content

Instantly share code, notes, and snippets.

@nopjia
Last active August 29, 2015 14:10
Show Gist options
  • Save nopjia/29bdbe7af788e21ab1af to your computer and use it in GitHub Desktop.
Save nopjia/29bdbe7af788e21ab1af to your computer and use it in GitHub Desktop.
SimpleUpdateLoop
var SimpleUpdateLoop = function() {
var _self = this;
var _requestId;
this.onUpdate = function(timestamp) {}; // function to implement
var _update = function(timestamp) {
_self.onUpdate(timestamp);
_requestId = window.requestAnimationFrame(_update);
};
this.start = function() {
if (!_requestId) {
_update();
}
};
this.stop = function() {
if (_requestId) {
window.cancelAnimationFrame(_requestId);
_requestId = undefined;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment