From eb78a44f791695a0202fa4b68511d95d6ff866f1 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Tue, 4 Nov 2014 12:46:48 -0800 Subject: [PATCH] adding music --- src/play_clj/core.clj | 2 +- src/play_clj/core_basics.clj | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index fa6b39b..a079f36 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -5,7 +5,7 @@ [play-clj.utils :as u]) (:import [com.badlogic.gdx Application Audio Files Game Gdx Graphics Input InputMultiplexer InputProcessor Net Preferences Screen] - [com.badlogic.gdx.audio Sound] + [com.badlogic.gdx.audio Sound Music] [com.badlogic.gdx.assets AssetManager] [com.badlogic.gdx.assets.loaders AsynchronousAssetLoader ParticleEffectLoader] diff --git a/src/play_clj/core_basics.clj b/src/play_clj/core_basics.clj index 167a94b..86fc1ff 100644 --- a/src/play_clj/core_basics.clj +++ b/src/play_clj/core_basics.clj @@ -169,3 +169,30 @@ [object k & options] `(let [^Sound object# ~object] (u/call! object# ~k ~@options))) + + +(defn music* + [path] + (let [^FileHandle fh (if (string? path) + (files! :internal path) + path)] + (or (u/load-asset (.path fh) Music) + (audio! :new-music fh)))) + +(defmacro music + "Returns a [Sound](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/audio/Sound.html). + + (sound \"playerhurt.wav\") + (sound \"playerhurt.wav\" :play)" + [path & options] + `(let [^Music object# (music* ~path)] + (u/calls! object# ~@options))) + +(defmacro music! + "Calls a single method on a `sound`. + + (sound! object :play) + (sound! object :dispose)" + [object k & options] + `(let [^Music object# ~object] + (u/call! object# ~k ~@options)))