public class GestureDetector extends InputAdapter
InputProcessor
implementation that detects gestures (tap, long press, fling, pan, zoom, pinch) and hands them to a
GestureDetector.GestureListener
.Modifier and Type | Class and Description |
---|---|
static class |
GestureDetector.GestureAdapter
Derrive from this if you only want to implement a subset of
GestureDetector.GestureListener . |
static interface |
GestureDetector.GestureListener
Register an instance of this class with a
GestureDetector to receive gestures such as taps, long presses, flings,
panning or pinch zooming. |
Constructor and Description |
---|
GestureDetector(float halfTapRectangleWidth,
float halfTapRectangleHeight,
float tapCountInterval,
float longPressDuration,
float maxFlingDelay,
GestureDetector.GestureListener listener) |
GestureDetector(float halfTapSquareSize,
float tapCountInterval,
float longPressDuration,
float maxFlingDelay,
GestureDetector.GestureListener listener) |
GestureDetector(GestureDetector.GestureListener listener)
Creates a new GestureDetector with default values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f,
maxFlingDelay=Integer.MAX_VALUE.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel()
No further gesture events will be triggered for the current touch, if any.
|
void |
invalidateTapSquare()
The tap square will no longer be used for the current touch.
|
boolean |
isLongPressed() |
boolean |
isLongPressed(float duration) |
boolean |
isPanning() |
void |
reset() |
void |
setLongPressSeconds(float longPressSeconds) |
void |
setMaxFlingDelay(long maxFlingDelay) |
void |
setTapCountInterval(float tapCountInterval) |
void |
setTapRectangleSize(float halfTapRectangleWidth,
float halfTapRectangleHeight) |
void |
setTapSquareSize(float halfTapSquareSize) |
boolean |
touchDown(float x,
float y,
int pointer,
int button) |
boolean |
touchDown(int x,
int y,
int pointer,
int button)
Called when the screen was touched or a mouse button was pressed.
|
boolean |
touchDragged(float x,
float y,
int pointer) |
boolean |
touchDragged(int x,
int y,
int pointer)
Called when a finger or the mouse was dragged.
|
boolean |
touchUp(float x,
float y,
int pointer,
int button) |
boolean |
touchUp(int x,
int y,
int pointer,
int button)
Called when a finger was lifted or a mouse button was released.
|
keyDown, keyTyped, keyUp, mouseMoved, scrolled
public GestureDetector(GestureDetector.GestureListener listener)
public GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener)
halfTapSquareSize
- half width in pixels of the square around an initial touch event, see
GestureDetector.GestureListener.tap(float, float, int, int)
.tapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.longPressDuration
- time in seconds that must pass for the detector to fire a
GestureDetector.GestureListener.longPress(float, float)
event.maxFlingDelay
- no fling event is fired when the time in seconds the finger was dragged is larger than this, see
GestureDetector.GestureListener.fling(float, float, int)
public GestureDetector(float halfTapRectangleWidth, float halfTapRectangleHeight, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener)
halfTapRectangleWidth
- half width in pixels of the rectangle around an initial touch event, see
GestureDetector.GestureListener.tap(float, float, int, int)
.halfTapRectangleHeight
- half height in pixels of the rectangle around an initial touch event, see
GestureDetector.GestureListener.tap(float, float, int, int)
.tapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.longPressDuration
- time in seconds that must pass for the detector to fire a
GestureDetector.GestureListener.longPress(float, float)
event.maxFlingDelay
- no fling event is fired when the time in seconds the finger was dragged is larger than this, see
GestureDetector.GestureListener.fling(float, float, int)
public boolean touchDown(int x, int y, int pointer, int button)
InputProcessor
Input.Buttons.LEFT
on iOS.touchDown
in interface InputProcessor
touchDown
in class InputAdapter
x
- The x coordinate, origin is in the upper left cornery
- The y coordinate, origin is in the upper left cornerpointer
- the pointer for the event.button
- the buttonpublic boolean touchDown(float x, float y, int pointer, int button)
public boolean touchDragged(int x, int y, int pointer)
InputProcessor
touchDragged
in interface InputProcessor
touchDragged
in class InputAdapter
pointer
- the pointer for the event.public boolean touchDragged(float x, float y, int pointer)
public boolean touchUp(int x, int y, int pointer, int button)
InputProcessor
Input.Buttons.LEFT
on iOS.touchUp
in interface InputProcessor
touchUp
in class InputAdapter
pointer
- the pointer for the event.button
- the buttonpublic boolean touchUp(float x, float y, int pointer, int button)
public void cancel()
public boolean isLongPressed()
public boolean isLongPressed(float duration)
duration
- public boolean isPanning()
public void reset()
public void invalidateTapSquare()
public void setTapSquareSize(float halfTapSquareSize)
public void setTapRectangleSize(float halfTapRectangleWidth, float halfTapRectangleHeight)
public void setTapCountInterval(float tapCountInterval)
tapCountInterval
- time in seconds that must pass for two touch down/up sequences to be detected as consecutive
taps.public void setLongPressSeconds(float longPressSeconds)
public void setMaxFlingDelay(long maxFlingDelay)