From a8a980a569e0c122e04d97acb8c0301512a3e927 Mon Sep 17 00:00:00 2001 From: oakes Date: Wed, 9 Apr 2014 18:19:55 -0400 Subject: [PATCH] Add bundle --- src/play_clj/core.clj | 2 +- src/play_clj/core_utils.clj | 10 ++++++++++ src/play_clj/entities.clj | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index 213bb0f..25f2d07 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -27,7 +27,7 @@ [com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener Align ChangeListener ClickListener DragListener FocusListener] [com.badlogic.gdx.utils ScreenUtils Timer$Task] - [play_clj.entities ShapeEntity])) + [play_clj.entities BundleEntity ShapeEntity])) (load "core_basics") (load "core_cameras") diff --git a/src/play_clj/core_utils.clj b/src/play_clj/core_utils.clj index 0d2c529..bfa33ba 100644 --- a/src/play_clj/core_utils.clj +++ b/src/play_clj/core_utils.clj @@ -7,6 +7,16 @@ [& body] `(app! :post-runnable (fn [] ~@body))) +(defn bundle + "Returns an entity containing other entities. This is a useful way to keep +related entities together. They will be drawn in the order they appear in the +internal :entities vector. + + (bundle (shape :filled) (texture \"image.png\")) + (assoc (bundle) :entities [])" + [& entities] + (BundleEntity. entities)) + (defn screenshot! "Captures a screenshot and either returns it as a `pixmap` or saves it to the specified path. diff --git a/src/play_clj/entities.clj b/src/play_clj/entities.clj index 1b1653a..9c5e6df 100644 --- a/src/play_clj/entities.clj +++ b/src/play_clj/entities.clj @@ -73,3 +73,8 @@ (.begin object type) (draw!) (.end object))) + +(defrecord BundleEntity [entities] Entity + (draw-entity! [{:keys [entities]} screen batch] + (doseq [e entities] + (draw-entity! e screen batch))))