Class Command
public abstract class Command
extends java.lang.Object
Control
from an InputDevice
can
be coupled to various player actions and passed to a Puppet
object.
More generally, whenever you want to create a new action the player can perform- such as walking, jumping, or shooting, you'll define that behavior in an object that extends this class. Objects of this type are automatically supplied with information about the current state of the players input device. This information in conjunction with several convenience methods provided by the parent class can be used to create player actions that exhibit a high level of fidelity.
The command superclass lacks constructors by design to encourage subclasses to define their own. This open-ended approach allows subclasses to capture whatever supplemental information they require to sufficiently perform the player actions they've been assigned to.
- Since:
- 2.0.0
- See Also:
axisMoved()
,buttonPressed()
,buttonPressedOnce()
,getInputValue()
,triggerPulled()
-
Constructor Summary
Constructors Constructor Description Command()
-
Method Summary
Modifier and Type Method Description protected boolean
axisMoved()
Convenience method used to check if the input state of theControl
coupled to this command is of a certain value.protected boolean
buttonPressed()
Convenience method used to check if the input state of theControl
coupled to this command is of a certain value.protected boolean
buttonPressedOnce()
Convenience method used to check if the input state of theControl
coupled to this command is of a certain value.abstract void
execute()
Organizes the input logic used to control player actions.protected int
getDeviceID()
Obtains the ID number of the device currently executing this command.protected float
getDeviceSetting(java.lang.String name)
Provides subclasses with a value that denotes some preference of the input device currently being used to execute this command.protected float
getInputValue()
Provides subclasses with a value describing the current state of theControl
coupled to this command.protected boolean
triggerPulled()
Convenience method used to check if the input state of theControl
coupled to this command is of a certain value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
Command
public Command()
-
-
Method Details
-
execute
public abstract void execute()Organizes the input logic used to control player actions. This method is called automatically once every game tick. -
getInputValue
protected float getInputValue()Provides subclasses with a value describing the current state of theControl
coupled to this command. The value provided may be between -1 to 1 or 0 to 1 depending on the input device used and the interactive component being pressed.- Returns:
- a value denoting the current state of a single interactive component on the input device
-
getDeviceSetting
protected float getDeviceSetting(java.lang.String name)Provides subclasses with a value that denotes some preference of the input device currently being used to execute this command.NOTE: By default the engine provides deadzone settings for both the left and right analog sticks of each input device. These settings determine how much a stick will need to be moved before its input is recognized. The values of these settings can be queried with "leftDeadzone" and "rightDeadzone" respectively.
Additional settings can be defined with
Input.setDeviceSetting(int, String, float)
.- Parameters:
name
- the name of the setting to parse a value from- Returns:
- the value of the setting or
NaN
if the setting of the name specified could not be found
-
getDeviceID
protected int getDeviceID()Obtains the ID number of the device currently executing this command.- Returns:
- a value indicating which input device is being used
-
buttonPressed
protected boolean buttonPressed()Convenience method used to check if the input state of theControl
coupled to this command is of a certain value. This is useful when we want to check if a button on aGamepad
has is being held down.Generally speaking gamepad buttons include:
CROSS
CIRCLE
SQUARE
TRIANGLE
DPAD_UP
DPAD_DOWN
DPAD_LEFT
DPAD_RIGHT
L1
R1
L3
R3
If you wish to check whether a button has been pressed once use
buttonPressedOnce()
.- Returns:
- true if the input value of the interactive component equals 1
-
buttonPressedOnce
protected boolean buttonPressedOnce()Convenience method used to check if the input state of theControl
coupled to this command is of a certain value. This is useful for when we want a command to only execute once per button press.Generally speaking gamepad buttons include:
CROSS
CIRCLE
SQUARE
TRIANGLE
DPAD_UP
DPAD_DOWN
DPAD_LEFT
DPAD_RIGHT
L1
R1
L3
R3
- Returns:
- true if the input value of the interactive component equals 1 but only upon its initial press
-
axisMoved
protected boolean axisMoved()Convenience method used to check if the input state of theControl
coupled to this command is of a certain value. This is especially useful when we want to determine whether an analog stick on theGamepad
has been moved.NOTE: It's important to remember that analog sticks are notoriously unreliable in the sense that their resting values rarely reach true zero. To mitigate this effect input devices provide what's known as a "deadzone" value to indicate how much an analog stick is allowed to move before it's recognized as a conscious decision on the players part. Therefore, the result of this check may not always yield true even if an analog stick is ostensibly moved.
Analog sticks are grouped by their axes;
LEFT_STICK_X
LEFT_STICK_Y
RIGHT_STICK_X
RIGHT_STICK_Y
- Returns:
- true if the input value of the interactive component exhibits a greater absolute value than the deadzone value
-
triggerPulled
protected boolean triggerPulled()Convenience method used to check if the input state of theControl
coupled to this command is of a certain value. This is useful anytime we want to detect a change in the value of a responsive trigger.Triggers on
Gamepad
style controllers may exhibit fluid input values much in the same way analog sticks do. Their function is significantly more predictable however so no deadzone value is used when determining its pulled state.The interactive components used to represent triggers are
L2
andR2
.- Returns:
- true if the input value of the interactive component is greater
than -1 (or 0 in the instance of
KeyMouseCombo
)
-