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