From 57c32ea71fb817f90053c7be31cc1d1a680676c2 Mon Sep 17 00:00:00 2001 From: oakes Date: Wed, 12 Feb 2014 18:58:14 -0500 Subject: [PATCH] Add sorting functions --- src/play_clj/core_graphics.clj | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index e01c5f9..f191375 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -1,5 +1,26 @@ (in-ns 'play-clj.core) +; misc + +(defmacro usage + "Returns a static field in [VertexAttributes.Usage](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/VertexAttributes.Usage.html)" + [k] + `~(u/gdx-field :graphics "VertexAttributes$Usage" (u/key->pascal k))) + +(defn low->high + "Sorts the `entities` by `k` in ascending order + + (low->high :y entities)" + [k entities] + (sort #(if (< (get %1 k) (get %2 k)) -1 1) entities)) + +(defn high->low + "Sorts the `entities` by `k` in descending order + + (high->low :y entities)" + [k entities] + (sort #(if (< (get %1 k) (get %2 k)) 1 -1) entities)) + ; tiled maps (defn tiled-map* @@ -420,7 +441,7 @@ specify which layers to render with or without (.begin batch) (doseq [entity (->> (map #(get-in screen [:layers %]) layer-names) (apply concat entities) - (sort #(if (< (:y %1) (:y %2)) 1 -1)))] + (high->low :y))] (if-let [layer (:layer entity)] (.renderTileLayer renderer layer) (draw-entity! batch entity))) @@ -543,10 +564,3 @@ remains in tact (let [^Camera camera (u/get-obj screen :camera)] (set! (. camera far) n) (.update camera))) - -; misc - -(defmacro usage - "Returns a static field in [VertexAttributes.Usage](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/VertexAttributes.Usage.html)" - [k] - `~(u/gdx-field :graphics "VertexAttributes$Usage" (u/key->pascal k)))