Allow adding/removing entities

This commit is contained in:
oakes
2013-12-29 15:30:15 -05:00
parent 9088f9906b
commit 8f97c3fa57
2 changed files with 29 additions and 9 deletions

View File

@@ -49,7 +49,7 @@
; draw entities
(defmulti sprite-batch (fn [screen] (class (:renderer screen))) :default nil)
(defmulti sprite-batch #(-> % :renderer class) :default nil)
(defmethod sprite-batch nil [screen]
(SpriteBatch.))
@@ -58,10 +58,13 @@
(.getSpriteBatch (:renderer screen)))
(defn draw-entities!
[screen entities]
(let [batch (sprite-batch screen)]
(.begin batch)
(doseq [{:keys [image x y width height]} entities]
(when (and image x y width height)
(.draw batch image x y width height)))
(.end batch)))
([screen]
(draw-entities! screen (-> screen :entities)))
([screen entities]
(let [batch (sprite-batch screen)]
(.begin batch)
(doseq [{:keys [image x y width height]} entities]
(when (and image x y width height)
(.draw batch image x y width height)))
(.end batch)
batch)))