Make the camera position functions work on vector-2 and vector-3 objects
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
IsometricStaggeredTiledMapRenderer
|
||||
IsometricTiledMapRenderer
|
||||
OrthogonalTiledMapRenderer]
|
||||
[com.badlogic.gdx.math Vector2 Vector3]
|
||||
[com.badlogic.gdx.scenes.scene2d Actor Stage]
|
||||
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener Align
|
||||
ChangeListener ClickListener DragListener FocusListener]
|
||||
@@ -202,10 +203,10 @@ via the screen map.
|
||||
entities)
|
||||
:on-pinch ; the user performed a pinch zoom gesture
|
||||
(fn [screen entities]
|
||||
(println (:initial-pointer-1 screen)) ; the x/y start position of finger 1
|
||||
(println (:initial-pointer-2 screen)) ; the x/y start position of finger 2
|
||||
(println (:pointer-1 screen)) ; the x/y end position of finger 1
|
||||
(println (:pointer-2 screen)) ; the x/y end position of finger 2
|
||||
(println (:initial-pointer-1 screen)) ; the start position of finger 1 (see the x and y functions)
|
||||
(println (:initial-pointer-2 screen)) ; the start position of finger 2 (see the x and y functions)
|
||||
(println (:pointer-1 screen)) ; the end position of finger 1 (see the x and y functions)
|
||||
(println (:pointer-2 screen)) ; the end position of finger 2 (see the x and y functions)
|
||||
entities)
|
||||
:on-tap ; the user tapped
|
||||
(fn [screen entities]
|
||||
@@ -380,10 +381,10 @@ via the screen map.
|
||||
:on-ui-pinch ; the user performed a pinch zoom gesture
|
||||
(fn [screen entities]
|
||||
(println (:event screen)) ; the InputEvent - http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/InputEvent.html
|
||||
(println (:initial-pointer-1 screen)) ; the x/y start position of finger 1
|
||||
(println (:initial-pointer-2 screen)) ; the x/y start position of finger 2
|
||||
(println (:pointer-1 screen)) ; the x/y end position of finger 1
|
||||
(println (:pointer-2 screen)) ; the x/y end position of finger 2
|
||||
(println (:initial-pointer-1 screen)) ; the start position of finger 1 (see the x and y functions)
|
||||
(println (:initial-pointer-2 screen)) ; the start position of finger 2 (see the x and y functions)
|
||||
(println (:pointer-1 screen)) ; the end position of finger 1 (see the x and y functions)
|
||||
(println (:pointer-2 screen)) ; the end position of finger 2 (see the x and y functions)
|
||||
entities)
|
||||
:on-ui-tap ; the user tapped
|
||||
(fn [screen entities]
|
||||
|
||||
@@ -82,43 +82,70 @@ remains in tact.
|
||||
(size! screen (* new-height (/ (game :width) (game :height))) new-height))
|
||||
|
||||
(defn x
|
||||
"Returns the x position of the camera in `screen`."
|
||||
[screen]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(. (. camera position) x)))
|
||||
"Returns the x position of `object`. If `object` is a screen, the x position
|
||||
of the camera will be returned."
|
||||
[object]
|
||||
(cond
|
||||
(isa? (type object) Vector2) (. ^Vector2 object x)
|
||||
(isa? (type object) Vector3) (. ^Vector3 object x)
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(. (. camera position) x))))
|
||||
|
||||
(defn x!
|
||||
"Sets only the x position of the camera in `screen`."
|
||||
[screen x-val]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(set! (. (. camera position) x) x-val)
|
||||
(.update camera)))
|
||||
"Sets only the x position of `object`. If `object` is a screen, the x position
|
||||
of the camera will be set."
|
||||
[object x-val]
|
||||
(cond
|
||||
(isa? (type object) Vector2) (let [^Vector2 v object]
|
||||
(.set v x-val (. v y)))
|
||||
(isa? (type object) Vector3) (let [^Vector3 v object]
|
||||
(.set v x-val (. v y) (. v z)))
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(set! (. (. camera position) x) x-val)
|
||||
(.update camera))))
|
||||
|
||||
(defn y
|
||||
"Returns the y position of the camera in `screen`."
|
||||
[screen]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(. (. camera position) y)))
|
||||
"Returns the y position of `object`. If `object` is a screen, the y position
|
||||
of the camera will be returned."
|
||||
[object]
|
||||
(cond
|
||||
(isa? (type object) Vector2) (. ^Vector2 object y)
|
||||
(isa? (type object) Vector3) (. ^Vector3 object y)
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(. (. camera position) y))))
|
||||
|
||||
(defn y!
|
||||
"Sets only the y position of the camera in `screen`."
|
||||
[screen y-val]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(set! (. (. camera position) y) y-val)
|
||||
(.update camera)))
|
||||
"Sets only the y position of `object`. If `object` is a screen, the y position
|
||||
of the camera will be set."
|
||||
[object y-val]
|
||||
(cond
|
||||
(isa? (type object) Vector2) (let [^Vector2 v object]
|
||||
(.set v (. v x) y-val))
|
||||
(isa? (type object) Vector3) (let [^Vector3 v object]
|
||||
(.set v (. v x) y-val (. v z)))
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(set! (. (. camera position) y) y-val)
|
||||
(.update camera))))
|
||||
|
||||
(defn z
|
||||
"Returns the z position of the camera in `screen`."
|
||||
[screen]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(. (. camera position) z)))
|
||||
"Returns the z position of `object`. If `object` is a screen, the z position
|
||||
of the camera will be returned."
|
||||
[object]
|
||||
(cond
|
||||
(isa? (type object) Vector3) (. ^Vector3 object z)
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(. (. camera position) z))))
|
||||
|
||||
(defn z!
|
||||
"Sets only the z position of the camera in `screen`."
|
||||
[screen z-val]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(set! (. (. camera position) z) z-val)
|
||||
(.update camera)))
|
||||
"Sets only the z position of `object`. If `object` is a screen, the z position
|
||||
of the camera will be set."
|
||||
[object z-val]
|
||||
(cond
|
||||
(isa? (type object) Vector3) (let [^Vector3 v object]
|
||||
(.set v (. v x) (. v y) z-val))
|
||||
:else (let [^Camera camera (u/get-obj object :camera)]
|
||||
(set! (. (. camera position) z) z-val)
|
||||
(.update camera))))
|
||||
|
||||
(defn position
|
||||
"Returns the position of the camera in `screen`."
|
||||
@@ -127,18 +154,17 @@ remains in tact.
|
||||
(. camera position)))
|
||||
|
||||
(defn position!
|
||||
"Sets the position of the camera in `screen`."
|
||||
([screen pos]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(set! (. camera position) pos)))
|
||||
([screen x-val y-val]
|
||||
(position! screen x-val y-val nil))
|
||||
([screen x-val y-val z-val]
|
||||
(let [^Camera camera (u/get-obj screen :camera)]
|
||||
(when x-val (set! (. (. camera position) x) x-val))
|
||||
(when y-val (set! (. (. camera position) y) y-val))
|
||||
(when z-val (set! (. (. camera position) z) z-val))
|
||||
(.update camera))))
|
||||
"Sets the position of `object`. If `object` is a screen, the position of the
|
||||
camera will be set."
|
||||
([object vec-3]
|
||||
(let [^Camera camera (u/get-obj object :camera)]
|
||||
(set! (. camera position) vec-3)))
|
||||
([object x-val y-val]
|
||||
(position! object x-val y-val nil))
|
||||
([object x-val y-val z-val]
|
||||
(when x-val (x! object x-val))
|
||||
(when y-val (y! object y-val))
|
||||
(when z-val (z! object z-val))))
|
||||
|
||||
(defn direction
|
||||
"Returns the direction of the camera in `screen`."
|
||||
|
||||
@@ -395,12 +395,14 @@
|
||||
(Vector2. x y)))
|
||||
|
||||
(defmacro vector-2
|
||||
"Returns a [Vector2](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html)."
|
||||
"Returns a [Vector2](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector2.html).
|
||||
The values can be retrieved with `x` and `y`, and modified with `x!` and `y!`."
|
||||
[x y & options]
|
||||
`(u/calls! ^Vector2 (vector-2* ~x ~y) ~@options))
|
||||
|
||||
(defmacro vector-2!
|
||||
"Calls a single method on a `vector-2`."
|
||||
"Calls a single method on a `vector-2`. If you're trying to modify the values,
|
||||
see `x!` and `y!`."
|
||||
[object k & options]
|
||||
`(u/call! ^Vector2 ~object ~k ~@options))
|
||||
|
||||
@@ -413,12 +415,15 @@
|
||||
(Vector3. x y z)))
|
||||
|
||||
(defmacro vector-3
|
||||
"Returns a [Vector3](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector3.html)."
|
||||
"Returns a [Vector3](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Vector3.html).
|
||||
The values can be retrieved with `x`, `y` and `z`, and modified with `x!`, `y!`,
|
||||
and `z!`."
|
||||
[x y z & options]
|
||||
`(u/calls! ^Vector3 (vector-3* ~x ~y ~z) ~@options))
|
||||
|
||||
(defmacro vector-3!
|
||||
"Calls a single method on a `vector-3`."
|
||||
"Calls a single method on a `vector-3`. If you're trying to modify the values,
|
||||
see `x!`, `y!`, and `z!`."
|
||||
[object k & options]
|
||||
`(u/call! ^Vector3 ~object ~k ~@options))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user