Search code examples
androidclojureaccelerometergyroscopeplay-clj

play-clj Android: Access accelerometer


I want to try an acceleration-based application in play-clj, but I'm not quite sure how to access gyroscope and accelerometer from clojure.

In Java I'd access Gdx.input.getAccelerometerX(). play-clj does not offer matching events in its defscreen macro, and I can't figure out the syntax to call the Gdx.input-accelerometer directly.

(import 'com.badlogic.gdx.Gdx) ;; Gdx should be a singleton, right?
(.-input Gdx) ;; no such field
(.input Gdx)  ;; no such method

Now what should I do? Should I prefer to access the device's sensors directly?


Solution

  • I don't know anything about Gdx, but the Javadoc for com.badlogic.gdx.Gdx tells me that Gdx.input is a static field of the Gdx class, not the field of a singleton instance.

    The correct Java interop should therefore be:

    (import 'com.badlogic.gdx.Gdx)
    (.getGyroscopeX Gdx/input)