Created
September 1, 2017 16:35
-
-
Save RSNara/38b53e25f867a7298641b729c8c580ad to your computer and use it in GitHub Desktop.
A requestAnimationFrame loop that's useful as a game loop.
This file contains hidden or 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
(defn raf-loop [func] | |
(let [stop (atom false) | |
id (atom nil)] | |
(reset! id (.requestAnimationFrame js/window | |
(fn helper [& args] | |
(when-not @stop | |
(reset! id (.requestAnimationFrame js/window helper)) | |
(try | |
(apply func args) | |
(catch js/Error ex | |
(reset! stop true) | |
(throw ex))))))) | |
#(reset! stop true))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment