From 43b706dccc96d15a77532e49288291a84518e7f3 Mon Sep 17 00:00:00 2001 From: oakes Date: Sat, 25 Jan 2014 00:25:46 -0500 Subject: [PATCH] Add particle-effect --- src/play_clj/core.clj | 3 ++- src/play_clj/core_graphics.clj | 8 ++++++++ src/play_clj/g2d.clj | 33 ++++++++++++++++++++++++++++++++- src/play_clj/utils.clj | 7 ++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index d7ff929..3b00363 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -5,7 +5,8 @@ [com.badlogic.gdx.audio Sound] [com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera PerspectiveCamera] - [com.badlogic.gdx.graphics.g2d NinePatch SpriteBatch TextureRegion] + [com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch + TextureRegion] [com.badlogic.gdx.input GestureDetector GestureDetector$GestureListener] [com.badlogic.gdx.maps MapLayer MapLayers] diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index 54012ef..743e0ab 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -226,6 +226,14 @@ with the tiled map file at `path` and `unit` scale height (float (or height (.getTotalHeight object)))] (.draw object batch x y width height))) +(defmethod draw-entity! :particle-effect + [^SpriteBatch batch {:keys [^ParticleEffect object x y]}] + (assert object) + (let [x (float (or x 0)) + y (float (or y 0))] + (.setPosition object x y) + (.draw object batch (graphics! :get-delta-time)))) + (defmethod draw-entity! :actor [^SpriteBatch batch {:keys [^Actor object] :as entity}] (assert object) diff --git a/src/play_clj/g2d.clj b/src/play_clj/g2d.clj index 6fe6aec..71b7cb5 100644 --- a/src/play_clj/g2d.clj +++ b/src/play_clj/g2d.clj @@ -2,7 +2,7 @@ (:require [play-clj.utils :as u]) (:import [com.badlogic.gdx.graphics Texture] [com.badlogic.gdx.graphics.g2d Animation BitmapFont NinePatch - TextureRegion])) + ParticleEffect TextureRegion])) (defmacro bitmap-font "Returns a [BitmapFont](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/BitmapFont.html) @@ -12,6 +12,8 @@ [& options] `(BitmapFont. ~@options)) +; texture + (defn texture* "The function version of `texture`" [arg] @@ -45,6 +47,8 @@ [entity k & options] `(u/call! ^TextureRegion (u/get-obj ~entity :object) ~k ~@options)) +; nine-patch + (defn nine-patch* "The function version of `nine-patch`" [arg] @@ -80,6 +84,33 @@ [entity k & options] `(u/call! ^NinePatch (u/get-obj ~entity :object) ~k ~@options)) +; particle-effect + +(defn particle-effect* + "The function version of `particle-effect`" + [] + (u/create-entity (ParticleEffect.))) + +(defmacro particle-effect + "Returns an entity based on [ParticleEffect](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/ParticleEffect.html) + + (particle-effect :load + (files! :internal \"fire.p\") + (files! :internal \"fire-images\"))" + [& options] + `(let [entity# (texture*)] + (u/calls! ^ParticleEffect (u/get-obj entity# :object) ~@options) + entity#)) + +(defmacro particle-effect! + "Calls a single method on a `particle-effect` + + (particle-effect! entity :set-position 10 10)" + [entity k & options] + `(u/call! ^ParticleEffect (u/get-obj ~entity :object) ~k ~@options)) + +; animation + (defmacro play-mode "Returns a static field from [Animation](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Animation.html) diff --git a/src/play_clj/utils.clj b/src/play_clj/utils.clj index 58a7a8a..4ad7f25 100644 --- a/src/play_clj/utils.clj +++ b/src/play_clj/utils.clj @@ -1,6 +1,7 @@ (ns play-clj.utils (:require [clojure.string :as s]) - (:import [com.badlogic.gdx.graphics.g2d NinePatch TextureRegion] + (:import [com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect + TextureRegion] [com.badlogic.gdx.scenes.scene2d Actor] [com.badlogic.gdx.utils Array ArrayMap])) @@ -197,6 +198,10 @@ new object to be created each time a field is set) [obj] {:type :nine-patch :object obj}) +(defmethod create-entity ParticleEffect + [obj] + {:type :particle-effect :object obj}) + (defmethod create-entity Actor [obj] {:type :actor :object obj})