Auto-destroy bodies

This commit is contained in:
oakes
2014-01-18 00:23:08 -05:00
parent e0371d4d28
commit da9b61c47e
2 changed files with 54 additions and 9 deletions

View File

@@ -12,14 +12,24 @@
(remove-input! renderer)
(add-input! renderer))
(defn ^:private update-box-2d!
[{:keys [^World world]} entities]
(when-not (.isLocked world)
(let [bodies (u/gdx-array [])]
(.getBodies world bodies)
(doseq [body bodies]
(when-not (some #(= body (:body %)) entities)
(.destroyBody world body))))))
(defn ^:private update-screen!
([{:keys [world g2dp-listener]}]
(when (isa? (type world) World)
(.setContactListener ^World world g2dp-listener)))
([{:keys [renderer] :as screen} entities]
(cond
(isa? (type renderer) Stage)
(update-stage! screen entities))))
([{:keys [renderer world] :as screen} entities]
(when (isa? (type renderer) Stage)
(update-stage! screen entities))
(when (isa? (type world) World)
(update-box-2d! screen entities))))
; tiled maps