SlideInput
Manages game input, using slide gestures as the direction knob and touch buttons as action keys. Note that you still need to add the touch buttons to the scene, and assigning them to action keys only manages event handling.
The way the directional knob works in SlideInput is that whenever the user touches a point in the screen where there is no action button, that point becomes the center of the knob, or the reference point. Now sliding away from the reference point indicates the direction of choice. If the user slides their finger to the left side of the reference point (the first point they touched), the knob will report a left direction and same holds for every other direction. The knob goes back to neutral as soon as the gesture is finished.
See Also:
Field Summary
Fields inherited from com.annahid.libs.artenus.input.GameInput
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
public | SlideInput() Creates a new instance of slide input, which can be added to a scene. |
Method Summary
Modifier and Type | Method and Description |
---|---|
public Button | getButton(int key) Gets the button mapped to the given controller key. |
public float | getRefX() Gets the x coordinate of the reference point, which is the first point the user touched to
trigger the direction knob. |
public float | getRefY() Gets the y coordinate of the reference point, which is the first point the user touched to
trigger the direction knob. |
public boolean | handleTouch(TouchEvent event) Handles touch events for this SlideInput. |
public boolean | hasBehavior(Behaviors behavior) Indicates whether this entity has the specified behavior. |
public void | onAttach(Scene scene) Registers this GameInput with the given scene. |
public void | onDetach(Scene scene) Unregisters this GameInput and releases resources associated with it. |
public void | setButton(int key, Button button) Assigns a touch button to an action key for this input manager. |
public void | setEffectiveArea(float x, float y, float width, float height) Sets the rectangular region on the screen where the knob input is captured. |
Methods inherited from com.annahid.libs.artenus.input.GameInput
getDirection
, getKeyMap
, hasBehavior
, holdKeyMap
, isKeyPressed
, onAttach
, onDetach
, pressKeys
, releaseKeyMap
, releaseKeys
, setListener
Methods inherited from java.lang.Object
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
Constructor Detail
SlideInput |
---|
public SlideInput()Creates a new instance of slide input, which can be added to a scene. |
Method Detail
getButton | ||
---|---|---|
public Button getButton( int key ) Gets the button mapped to the given controller key. Parameters:
Returns:
The button |
getRefX |
---|
public float getRefX() Gets the x coordinate of the reference point, which is the first point the user touched to
trigger the direction knob. This point is maintained until the next gesture. Returns:
The x component of the reference point. |
getRefY |
---|
public float getRefY() Gets the y coordinate of the reference point, which is the first point the user touched to
trigger the direction knob. This point is maintained until the next gesture. Returns:
The y component of the reference point. |
handleTouch |
---|
public boolean handleTouch( TouchEvent event ) Handles touch events for this SlideInput. Specified By:
Returns:
true if handled, false otherwise |
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. Overrides:
|
onAttach |
---|
public 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. Overrides:
|
onDetach |
---|
public void onDetach( Scene scene ) Unregisters this GameInput and releases resources associated with it. Overrides:
|
setButton | ||||
---|---|---|---|---|
public void setButton( int key, Button button ) Assigns a touch button to an action key for this input manager. Parameters:
See Also:
|
setEffectiveArea | ||||||||
---|---|---|---|---|---|---|---|---|
public void setEffectiveArea( float x, float y, float width, float height ) Sets the rectangular region on the screen where the knob input is captured. Parameters:
|