Created
September 28, 2013 11:34
-
-
Save kornysietsma/6741187 to your computer and use it in GitHub Desktop.
simple game loop that reads regular ajax results and also updates on every animation frame
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 game-loop [] | |
(let [anim-chan (au/anim-ch active) | |
ajax-chan (au/ajax-loop "world" slowth active)] | |
(go | |
(loop [state {:world {} :timestamp (js-now)}] | |
(when @active | |
(let [next-state | |
(alt! | |
anim-chan ([val] (do | |
(graphics/draw-map | |
ctx (:world state) (scaled-time val (:timestamp state))) | |
state)) ; no state change | |
ajax-chan ([val] {:world val :timestamp (js-now)}))] | |
(recur next-state))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment