Class DragListener
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.InputListener
-
- com.badlogic.gdx.scenes.scene2d.utils.DragListener
-
- All Implemented Interfaces:
EventListener
- Direct Known Subclasses:
DragScrollListener
public class DragListener extends InputListener
Detects mouse or finger touch drags on an actor. A touch must go down over the actor and a drag won't start until it is moved outside thetap square. Any touch (not just the first) will trigger this listener. While pressed, other touch downs are ignored.
-
-
Constructor Summary
Constructors Constructor Description DragListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()voiddrag(InputEvent event, float x, float y, int pointer)voiddragStart(InputEvent event, float x, float y, int pointer)voiddragStop(InputEvent event, float x, float y, int pointer)intgetButton()floatgetDeltaX()Returns the amount on the x axis that the touch has been dragged since the last drag event.floatgetDeltaY()Returns the amount on the y axis that the touch has been dragged since the last drag event.floatgetDragDistance()The distance from drag start to the current drag position.floatgetDragStartX()floatgetDragStartY()floatgetDragX()floatgetDragY()floatgetStageTouchDownX()floatgetStageTouchDownY()floatgetTapSquareSize()floatgetTouchDownX()floatgetTouchDownY()booleanisDragging()Returns true if a touch has been dragged outside the tap square.voidsetButton(int button)Sets the button to listen for, all other buttons are ignored.voidsetDragStartX(float dragStartX)voidsetDragStartY(float dragStartY)voidsetTapSquareSize(float halfTapSquareSize)booleantouchDown(InputEvent event, float x, float y, int pointer, int button)Called when a mouse button or a finger touch goes down on the actor.voidtouchDragged(InputEvent event, float x, float y, int pointer)Called when a mouse button or a finger touch is moved anywhere, but only if touchDown previously returned true for the mouse button or touch.voidtouchUp(InputEvent event, float x, float y, int pointer, int button)Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch.-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.InputListener
enter, exit, handle, keyDown, keyTyped, keyUp, mouseMoved, scrolled
-
-
-
-
Method Detail
-
touchDown
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
Description copied from class:InputListenerCalled when a mouse button or a finger touch goes down on the actor. If true is returned, this listener will havetouch focus, so it will receive all touchDragged and touchUp events, even those not over this actor, until touchUp is received. Also when true is returned, the event ishandled.- Overrides:
touchDownin classInputListener- See Also:
InputEvent
-
touchDragged
public void touchDragged(InputEvent event, float x, float y, int pointer)
Description copied from class:InputListenerCalled when a mouse button or a finger touch is moved anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchDragged event is alwayshandled.- Overrides:
touchDraggedin classInputListener- See Also:
InputEvent
-
touchUp
public void touchUp(InputEvent event, float x, float y, int pointer, int button)
Description copied from class:InputListenerCalled when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch. The touchUp event is alwayshandled.- Overrides:
touchUpin classInputListener- See Also:
InputEvent
-
dragStart
public void dragStart(InputEvent event, float x, float y, int pointer)
-
drag
public void drag(InputEvent event, float x, float y, int pointer)
-
dragStop
public void dragStop(InputEvent event, float x, float y, int pointer)
-
cancel
public void cancel()
-
isDragging
public boolean isDragging()
Returns true if a touch has been dragged outside the tap square.
-
setTapSquareSize
public void setTapSquareSize(float halfTapSquareSize)
-
getTapSquareSize
public float getTapSquareSize()
-
getTouchDownX
public float getTouchDownX()
-
getTouchDownY
public float getTouchDownY()
-
getStageTouchDownX
public float getStageTouchDownX()
-
getStageTouchDownY
public float getStageTouchDownY()
-
getDragStartX
public float getDragStartX()
-
setDragStartX
public void setDragStartX(float dragStartX)
-
getDragStartY
public float getDragStartY()
-
setDragStartY
public void setDragStartY(float dragStartY)
-
getDragX
public float getDragX()
-
getDragY
public float getDragY()
-
getDragDistance
public float getDragDistance()
The distance from drag start to the current drag position.
-
getDeltaX
public float getDeltaX()
Returns the amount on the x axis that the touch has been dragged since the last drag event.
-
getDeltaY
public float getDeltaY()
Returns the amount on the y axis that the touch has been dragged since the last drag event.
-
getButton
public int getButton()
-
setButton
public void setButton(int button)
Sets the button to listen for, all other buttons are ignored. Default isInput.Buttons.LEFT. Use -1 for any button.
-
-