|
@@ -127,7 +127,7 @@ Have a look at the code:
|
|
|
. In the same line, you also register “Rotate to an alternative mouse click trigger. +
|
|
. In the same line, you also register “Rotate to an alternative mouse click trigger. +
|
|
|
`new MouseButtonTrigger(MouseInput.BUTTON_LEFT)`
|
|
`new MouseButtonTrigger(MouseInput.BUTTON_LEFT)`
|
|
|
. You map the `Pause`, `Left`, `Right` mappings to the P, J, K keys, respectively.
|
|
. You map the `Pause`, `Left`, `Right` mappings to the P, J, K keys, respectively.
|
|
|
-
|
|
|
|
|
|
|
++
|
|
|
[source,java]
|
|
[source,java]
|
|
|
----
|
|
----
|
|
|
|
|
|
|
@@ -139,12 +139,12 @@ Have a look at the code:
|
|
|
new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
|
new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
|
|
|
|
|
|
|
|
----
|
|
----
|
|
|
-
|
|
|
|
|
|
|
++
|
|
|
Now you need to register your trigger mappings.
|
|
Now you need to register your trigger mappings.
|
|
|
|
|
|
|
|
. You register the pause action to the ActionListener, because it is an “on/off action.
|
|
. You register the pause action to the ActionListener, because it is an “on/off action.
|
|
|
. You register the movement actions to the AnalogListener, because they are gradual actions.
|
|
. You register the movement actions to the AnalogListener, because they are gradual actions.
|
|
|
-
|
|
|
|
|
|
|
++
|
|
|
[source,java]
|
|
[source,java]
|
|
|
----
|
|
----
|
|
|
|
|
|
|
@@ -265,7 +265,9 @@ Mappings registered to the *ActionListener* are digital either-or actions –
|
|
|
|
|
|
|
|
* Example: Pause button, shooting, selecting, jumping, one-time click interactions.
|
|
* Example: Pause button, shooting, selecting, jumping, one-time click interactions.
|
|
|
|
|
|
|
|
-*Tip:* It's very common that you want an action to be only triggered once, in the moment when the key is _released_. For instance when opening a door, flipping a boolean state, or picking up an item. To achieve that, you use an `ActionListener` and test for `… && !keyPressed`. For an example, look at the Pause button code:
|
|
|
|
|
|
|
+[TIP]
|
|
|
|
|
+====
|
|
|
|
|
+It's very common that you want an action to be only triggered once, in the moment when the key is _released_. For instance when opening a door, flipping a boolean state, or picking up an item. To achieve that, you use an `ActionListener` and test for `… && !keyPressed`. For an example, look at the Pause button code:
|
|
|
|
|
|
|
|
[source,java]
|
|
[source,java]
|
|
|
----
|
|
----
|
|
@@ -273,7 +275,7 @@ Mappings registered to the *ActionListener* are digital either-or actions –
|
|
|
isRunning = !isRunning;
|
|
isRunning = !isRunning;
|
|
|
}
|
|
}
|
|
|
----
|
|
----
|
|
|
-
|
|
|
|
|
|
|
+====
|
|
|
|
|
|
|
|
== Table of Triggers
|
|
== Table of Triggers
|
|
|
|
|
|
|
@@ -311,8 +313,10 @@ KeyTrigger(KeyInput.KEY_RIGHT)
|
|
|
|
|
|
|
|
|===
|
|
|===
|
|
|
|
|
|
|
|
-*Tip:* If you don't recall an input constant during development, you benefit from an IDE's code completion functionality: Place the caret after e.g. `KeyInput.|` and trigger code completion to select possible input identifiers.
|
|
|
|
|
-
|
|
|
|
|
|
|
+[TIP]
|
|
|
|
|
+====
|
|
|
|
|
+If you don't recall an input constant during development, you benefit from an IDE's code completion functionality: Place the caret after e.g. `KeyInput.|` and trigger code completion to select possible input identifiers.
|
|
|
|
|
+====
|
|
|
|
|
|
|
|
== Exercises
|
|
== Exercises
|
|
|
|
|
|