Package com.badlogic.gdx.input
Class GestureDetector
- java.lang.Object
-
- com.badlogic.gdx.InputAdapter
-
- com.badlogic.gdx.input.GestureDetector
-
- All Implemented Interfaces:
InputProcessor
- Direct Known Subclasses:
CameraInputController
public class GestureDetector extends InputAdapter
InputProcessorimplementation that detects gestures (tap, long press, fling, pan, zoom, pinch) and hands them to aGestureDetector.GestureListener.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGestureDetector.GestureAdapterDerrive from this if you only want to implement a subset ofGestureDetector.GestureListener.static interfaceGestureDetector.GestureListenerRegister an instance of this class with aGestureDetectorto receive gestures such as taps, long presses, flings, panning or pinch zooming.
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()No further gesture events will be triggered for the current touch, if any.voidinvalidateTapSquare()The tap square will no longer be used for the current touch.booleanisLongPressed()booleanisLongPressed(float duration)booleanisPanning()voidreset()voidsetLongPressSeconds(float longPressSeconds)voidsetMaxFlingDelay(long maxFlingDelay)voidsetTapCountInterval(float tapCountInterval)voidsetTapRectangleSize(float halfTapRectangleWidth, float halfTapRectangleHeight)voidsetTapSquareSize(float halfTapSquareSize)booleantouchCancelled(int screenX, int screenY, int pointer, int button)Called when the touch gesture is cancelled.booleantouchDown(float x, float y, int pointer, int button)booleantouchDown(int x, int y, int pointer, int button)Called when the screen was touched or a mouse button was pressed.booleantouchDragged(float x, float y, int pointer)booleantouchDragged(int x, int y, int pointer)Called when a finger or the mouse was dragged.booleantouchUp(float x, float y, int pointer, int button)booleantouchUp(int x, int y, int pointer, int button)Called when a finger was lifted or a mouse button was released.-
Methods inherited from class com.badlogic.gdx.InputAdapter
keyDown, keyTyped, keyUp, mouseMoved, scrolled
-
-
-
-
Constructor Detail
-
GestureDetector
public GestureDetector(GestureDetector.GestureListener listener)
Creates a new GestureDetector with default values: halfTapSquareSize=20, tapCountInterval=0.4f, longPressDuration=1.1f, maxFlingDelay=Integer.MAX_VALUE.
-
GestureDetector
public GestureDetector(float halfTapSquareSize, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener)- Parameters:
halfTapSquareSize- half width in pixels of the square around an initial touch event, seeGestureDetector.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 aGestureDetector.GestureListener.longPress(float, float)event.maxFlingDelay- no fling event is fired when the time in seconds the finger was dragged is larger than this, seeGestureDetector.GestureListener.fling(float, float, int)
-
GestureDetector
public GestureDetector(float halfTapRectangleWidth, float halfTapRectangleHeight, float tapCountInterval, float longPressDuration, float maxFlingDelay, GestureDetector.GestureListener listener)- Parameters:
halfTapRectangleWidth- half width in pixels of the rectangle around an initial touch event, seeGestureDetector.GestureListener.tap(float, float, int, int).halfTapRectangleHeight- half height in pixels of the rectangle around an initial touch event, seeGestureDetector.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 aGestureDetector.GestureListener.longPress(float, float)event.maxFlingDelay- no fling event is fired when the time in seconds the finger was dragged is larger than this, seeGestureDetector.GestureListener.fling(float, float, int)
-
-
Method Detail
-
touchDown
public boolean touchDown(int x, int y, int pointer, int button)Description copied from interface:InputProcessorCalled when the screen was touched or a mouse button was pressed. The button parameter will beInput.Buttons.LEFTon iOS.- Specified by:
touchDownin interfaceInputProcessor- Overrides:
touchDownin classInputAdapter- Parameters:
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 button- Returns:
- whether the input was processed
-
touchDown
public boolean touchDown(float x, float y, int pointer, int button)
-
touchDragged
public boolean touchDragged(int x, int y, int pointer)Description copied from interface:InputProcessorCalled when a finger or the mouse was dragged.- Specified by:
touchDraggedin interfaceInputProcessor- Overrides:
touchDraggedin classInputAdapterpointer- the pointer for the event.- Returns:
- whether the input was processed
-
touchDragged
public boolean touchDragged(float x, float y, int pointer)
-
touchUp
public boolean touchUp(int x, int y, int pointer, int button)Description copied from interface:InputProcessorCalled when a finger was lifted or a mouse button was released. The button parameter will beInput.Buttons.LEFTon iOS.- Specified by:
touchUpin interfaceInputProcessor- Overrides:
touchUpin classInputAdapterpointer- the pointer for the event.button- the button- Returns:
- whether the input was processed
-
touchUp
public boolean touchUp(float x, float y, int pointer, int button)
-
touchCancelled
public boolean touchCancelled(int screenX, int screenY, int pointer, int button)Description copied from interface:InputProcessorCalled when the touch gesture is cancelled. Reason may be from OS interruption to touch becoming a large surface such as the user cheek). Relevant on Android and iOS only. The button parameter will beInput.Buttons.LEFTon iOS.- Specified by:
touchCancelledin interfaceInputProcessor- Overrides:
touchCancelledin classInputAdapterpointer- the pointer for the event.button- the button- Returns:
- whether the input was processed
-
cancel
public void cancel()
No further gesture events will be triggered for the current touch, if any.
-
isLongPressed
public boolean isLongPressed()
- Returns:
- whether the user touched the screen long enough to trigger a long press event.
-
isLongPressed
public boolean isLongPressed(float duration)
- Parameters:
duration-- Returns:
- whether the user touched the screen for as much or more than the given duration.
-
isPanning
public boolean isPanning()
-
reset
public void reset()
-
invalidateTapSquare
public void invalidateTapSquare()
The tap square will no longer be used for the current touch.
-
setTapSquareSize
public void setTapSquareSize(float halfTapSquareSize)
-
setTapRectangleSize
public void setTapRectangleSize(float halfTapRectangleWidth, float halfTapRectangleHeight)
-
setTapCountInterval
public void setTapCountInterval(float tapCountInterval)
- Parameters:
tapCountInterval- time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.
-
setLongPressSeconds
public void setLongPressSeconds(float longPressSeconds)
-
setMaxFlingDelay
public void setMaxFlingDelay(long maxFlingDelay)
-
-