Show us some of your code.
Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood
Ok, so here is the ns declaration:
(ns msnake.gui (:require ...the core game namespaces) (:import ...a bunch of JavaFX classes) (:gen-class :extends javafx.application.Application))
And here is the `-start` method and the animation-timer in case anyone is wondering what that is:
(defn- animation-timer ^AnimationTimer [proceed-game!] (let [last-update (SimpleLongProperty. 0)] (proxy [AnimationTimer] [] (handle [now] (let [last-update* (.get last-update) nanos-elapsed (- now last-update*)] (when (>= nanos-elapsed @ctrl/turn-nanos) (proceed-game!) (.set last-update now))))))) (defn -start [app ^Stage stage] (let [player-no (new-game-dialog!) entities (ctrl/game-entities player-no) canvas (doto (Canvas. 750 500) (.setFocusTraversable true) (.setOnKeyPressed (fxut/event-handler [e] (apply react! e entities)))) root (StackPane. (into-array [canvas])) context (.getGraphicsContext2D canvas) scene (Scene. root 750 500) timer (animation-timer (partial paint/paint-all context entities)) audio (doto (MediaPlayer. (-> "PimPoy.wav" io/resource .toString (Media.))) (.setVolume start-volume) (.setAutoPlay true) (.setCycleCount MediaPlayer/INDEFINITE))] (deliver start-gui-loop #(.start timer)) (deliver audio-engine audio) (doto stage (.setResizable false) (.setTitle "MX SNAKE") (.setOnCloseRequest (fxut/event-handler [_] (System/exit 0))) (.setScene scene) (.show)) (fxut/run-later* @start-gui-loop)))
As you can see the MediaPlayer object is created once. It is accessed through various controllers (volume+/- etc) but never created anew. For example here is the handler for <M>:
KeyCode/M (fn [& _] (if (= MediaPlayer$Status/PLAYING (.getStatus @audio-engine)) (.stop @audio-engine) (.play @@audio-engine)))
Here is main.clj:
(ns msnake.main (:import (javafx.application Application) (msnake gui)) (:gen-class :main true)) (defn -main [& args] (Application/launch gui (into-array String args)))
and finally project.clj
(defproject msnake "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :dependencies [[org.clojure/clojure "1.9.0"]] :aot [msnake.gui msnake.paint msnake.main] :main msnake.main :jvm-opts ["-Dclojure.compiler.direct-linking=true"] )
I should point out that direct-linking is not the culprit here.
Exactly the same thing happens with or without direct-linking :(.
As you can see I'm playing by the book - i.e. subclassing Application, and launching through the overridden `-start` method.
Kind regards,
Dimitris
Darn it, i made a typo copying and it may throw some people off. There is a double-deref `@@` in the <M> handler i pasted. Apologies for the slopiness... :(
Regards,
Dimitris