From 9eba3bb28a7e5eaa48753a76babe279a0e20402d Mon Sep 17 00:00:00 2001 From: oakes Date: Sun, 19 Jan 2014 15:10:54 -0500 Subject: [PATCH] Set a texture entity's width and height when it is first created --- src/play_clj/core_graphics.clj | 9 +++------ src/play_clj/utils.clj | 7 +++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index e5a5e54..7a5092a 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -159,13 +159,10 @@ (.draw object batch 1)) (defmethod draw-entity! :texture - [^SpriteBatch batch {:keys [^TextureRegion object x y width height]}] + [^SpriteBatch batch {:keys [^TextureRegion object x y width height] + :or {x 0 y 0}}] (assert object) - (let [x (float (or x 0)) - y (float (or y 0)) - width (float (or width (.getRegionWidth object))) - height (float (or height (.getRegionHeight object)))] - (.draw batch object x y width height))) + (.draw batch object (float x) (float y) (float width) (float height))) (defn draw! [{:keys [renderer] :as screen} entities] (assert renderer) diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index d827826..e829455 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -137,8 +137,11 @@ (defmulti create-entity class) (defmethod create-entity TextureRegion - [obj] - {:type :texture :object obj}) + [^TextureRegion obj] + {:type :texture + :object obj + :width (.getRegionWidth obj) + :height (.getRegionHeight obj)}) (defmethod create-entity Actor [obj]