Artenus 2D Framework
Artenus Reference

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:

public final class SlideInput
extends GameInput
implements Touchable

Field Summary

Fields inherited from com.annahid.libs.artenus.input.GameInput

Constructor Summary

Modifier and TypeConstructor and Description
public SlideInput()
Creates a new instance of slide input, which can be added to a scene.

Method Summary

Modifier and TypeMethod and Description
public ButtongetButton(int key)
Gets the button mapped to the given controller key.
public floatgetRefX()
Gets the x coordinate of the reference point, which is the first point the user touched to trigger the direction knob.
public floatgetRefY()
Gets the y coordinate of the reference point, which is the first point the user touched to trigger the direction knob.
public booleanhandleTouch(TouchEvent event)
Handles touch events for this SlideInput.
public booleanhasBehavior(Behaviors behavior)
Indicates whether this entity has the specified behavior.
public voidonAttach(Scene scene)
Registers this GameInput with the given scene.
public voidonDetach(Scene scene)
Unregisters this GameInput and releases resources associated with it.
public voidsetButton(int key, Button button)
Assigns a touch button to an action key for this input manager.
public voidsetEffectiveArea(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

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:
keyController key
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:
keyThe action key to associate with
buttonThe touch button to be added (or null to disassociate)
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:
xx coordinate of the top-left corner of the region
yy coordinate of the top-left corner of the region
widthWidth of the region
heightHeight of the region