Remove joints whose bodies no longer exist
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
IsometricStaggeredTiledMapRenderer
|
||||
IsometricTiledMapRenderer
|
||||
OrthogonalTiledMapRenderer]
|
||||
[com.badlogic.gdx.physics.box2d World]
|
||||
[com.badlogic.gdx.physics.box2d Joint World]
|
||||
[com.badlogic.gdx.scenes.scene2d Actor Stage]))
|
||||
|
||||
(load "core_global")
|
||||
|
||||
@@ -15,11 +15,18 @@
|
||||
(defn ^:private update-box-2d!
|
||||
[{:keys [^World world]} entities]
|
||||
(when-not (.isLocked world)
|
||||
(let [bodies (u/gdx-array [])]
|
||||
(.getBodies world bodies)
|
||||
(doseq [body bodies]
|
||||
(let [arr (u/gdx-array [])]
|
||||
; remove bodies that no longer exist
|
||||
(.getBodies world arr)
|
||||
(doseq [body arr]
|
||||
(when-not (some #(= body (:body %)) entities)
|
||||
(.destroyBody world body))))))
|
||||
(.destroyBody world body)))
|
||||
; remove joints whose bodies no longer exist
|
||||
(.getJoints world arr)
|
||||
(doseq [^Joint joint arr]
|
||||
(when (and (not (some #(= (.getBodyA joint) (:body %)) entities))
|
||||
(not (some #(= (.getBodyB joint) (:body %)) entities)))
|
||||
(.destroyJoint world joint))))))
|
||||
|
||||
(defn ^:private update-screen!
|
||||
([{:keys [world g2dp-listener]}]
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
(defn create-field-setters
|
||||
[obj {:keys [] :as args}]
|
||||
(map (fn [[k v]]
|
||||
`(set! (. ~obj ~(symbol (key->camel k))) (eval ~v)))
|
||||
`(set! (. ~obj ~(symbol (key->camel k))) ~v))
|
||||
args))
|
||||
|
||||
(defmacro fields!
|
||||
|
||||
Reference in New Issue
Block a user