Last active
August 29, 2015 14:10
-
-
Save nopjia/29bdbe7af788e21ab1af to your computer and use it in GitHub Desktop.
SimpleUpdateLoop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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