com.annahid.libs.artenus.input
GameInput
Superclass for all game input controllers. A game input manager maps inputs from a specific
source to the unified Artenus game controller pattern. A virtual controller in this framework has
a single direction knob and four action keys. The direction knob can indicate any possible
direction in a circle centered at the knob.
public abstract class GameInput implements Entity
Field Summary
Modifier and Type | Field and Description |
---|---|
public static final | KEY_ACTION1 Key identifier for the first action key. |
public static final | KEY_ACTION2 Key identifier for the second action key. |
public static final | KEY_ACTION3 Key identifier for the third action key. |
public static final | KEY_ACTION4 Key identifier for the fourth action key. |
protected | direction Holds the current direction of the knob. |
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
protected | GameInput() Creates an GameInput with all buttons unpressed and the directional knob at its rest
(0). |
Method Summary
Modifier and Type | Method and Description |
---|---|
public final Point2D | getDirection() Gets the status of the direction knob. |
public int | getKeyMap() Gets the complete key map. |
public boolean | hasBehavior(Behaviors behavior) Indicates whether this entity has the specified behavior. |
protected void | holdKeyMap() Holds the key map to process new input. |
public boolean | isKeyPressed(int keyCode) Determines whether the key (or any of the multiple keys) specified are currently in the
pressed state. |
public abstract void | onAttach(Scene scene) Registers this GameInput with the given scene. |
public abstract void | onDetach(Scene scene) Unregisters this GameInput and releases resources associated with it. |
protected void | pressKeys(int keyCode) Changes the status of a key or a combination of keys to pressed. |
protected void | releaseKeyMap() Releases the previously held key map. |
protected void | releaseKeys(int keyCode) Changes the status of a key or a combination of keys to released. |
public final void | setListener(InputListener listener) Sets the InputListener responsible for handling input status changes of this
GameInput. |
Methods inherited from java.lang.Object
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
Field Detail
KEY_ACTION1 |
---|
public static final KEY_ACTION1 Key identifier for the first action key. |
KEY_ACTION2 |
---|
public static final KEY_ACTION2 Key identifier for the second action key. |
KEY_ACTION3 |
---|
public static final KEY_ACTION3 Key identifier for the third action key. |
KEY_ACTION4 |
---|
public static final KEY_ACTION4 Key identifier for the fourth action key. |
direction |
---|
protected direction Holds the current direction of the knob. Subclasses are allowed to adjust the coordinates of
this field according to user input. However, this variable should never be set to
null or it will cause application crash. To keep up with the standard operation of
the framework's input system subclasses should normalize the direction (so the length of the
direction vector is always 1 or zero). |
Constructor Detail
GameInput |
---|
protected GameInput()Creates an GameInput with all buttons unpressed and the directional knob at its rest (0). |
Method Detail
getDirection |
---|
public final Point2D getDirection() Gets the status of the direction knob. Returns:
The direction vector. The length of the vector is normally either 1 or zero. |
getKeyMap |
---|
public int getKeyMap() Gets the complete key map. The key map is a bit-set containing information about the pressed
state of the keys. If you and the return value with any of the key identifiers, the
result will be zero if the corresponding key is not pressed, and non-zero otherwise. Returns:
The key map bitwise integer |
hasBehavior |
---|
public boolean hasBehavior( Behaviors behavior ) Indicates whether this entity has the specified behavior. If it does, it can be cast to the
corresponding interface. Note that the return value can be transient and a fixed return value
for a behavior is not guaranteed by the framework. Specified By:
Returns:
true if this entity has the behavior, false otherwise |
holdKeyMap |
---|
protected void holdKeyMap() Holds the key map to process new input. Subclasses must call this method before processing
input. Holding the key map helps determine whether the associated InputListener
should be called back. This method should be followed by releaseKeyMap() in order to
complete the processing of input.See Also:
|
isKeyPressed | ||
---|---|---|
public boolean isKeyPressed( int keyCode ) Determines whether the key (or any of the multiple keys) specified are currently in the
pressed state. Parameters:
Returns:
true if the key (or any of the keys} are pressed or false otherwise |
onAttach | ||
---|---|---|
public abstract void onAttach( Scene scene ) Registers this GameInput with the given scene. Some input managers might need some
initialization that needs context. This method is where they should initialize themselves. Parameters:
Specified By:
|
onDetach | ||
---|---|---|
public abstract void onDetach( Scene scene ) Unregisters this GameInput and releases resources associated with it. Parameters:
Specified By:
|
pressKeys | ||
---|---|---|
protected void pressKeys( int keyCode ) Changes the status of a key or a combination of keys to pressed. Subclasses should use this
method to alter the key map. This method must be called after a holdKeyMap() call
and before a releaseKeyMap() call. Otherwise the changes will not be reportedParameters:
|
releaseKeyMap |
---|
protected void releaseKeyMap() Releases the previously held key map. Once this method is called, the new key map and knob
direction are compared to their corresponding values before holding. In case of any change,
the associated InputListener will be called back to respond to the change. |
releaseKeys | ||
---|---|---|
protected void releaseKeys( int keyCode ) Changes the status of a key or a combination of keys to released. Subclasses should use this
method to alter the key map. This method must be called after a holdKeyMap() call
and before a releaseKeyMap() call. Otherwise the changes will not be reported.Parameters:
|
setListener | ||
---|---|---|
public final void setListener( InputListener listener ) Sets the InputListener responsible for handling input status changes of this
GameInput. Each time the key map or the direction changes, the listener is signaled
to process the event.Parameters:
See Also:
|