2

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?

waechtertroll
  • 607
  • 3
  • 17

1 Answers1

0

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)
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70
  • You're right... the possibility of a static field didn't come to my mind, I always used it as if it were a singleton when I wrote Java apps with it. Your solution works like a charm. – waechtertroll Feb 12 '16 at 08:35