APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.utils

public Class ClickListener

extends InputListener
Class Inheritance
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldClickListener
Imports
com.badlogic.gdx.Input.Buttons, com.badlogic.gdx.scenes.scene2d.Actor, .InputEvent, .InputListener, com.badlogic.gdx.utils.Null, .TimeUtils

Detects mouse over, mouse or finger touch presses, and clicks on an actor. A touch must go down over the actor and is considered pressed as long as it is over the actor or within the tap square. This behavior makes it easier to press buttons on a touch interface when the initial touch happens near the edge of the actor. Double clicks can be detected using getTapCount(). Any touch (not just the first) will trigger this listener. While pressed, other touch downs are ignored.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private int
private boolean
private boolean
private long
private boolean
private boolean
private int
private int
private int
private long
private float
private float
private float
public static float
visualPressedDuration

Time in seconds isVisualPressed() reports true after a press resulting in a click is released.

private long

Constructor Summary

AccessConstructor and Description
public
ClickListener()

Create a listener where clicked(InputEvent, float, float) is only called for left clicks.

public
ClickListener(int button)

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

If a touch down is being monitored, the over state and drag and touch up events are ignored until the next touch up.

public void
clicked(InputEvent event, float x, float y)

public void
enter(InputEvent event, float x, float y, int pointer, Actor fromActor)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.enter.

Called any time the mouse cursor or a finger touch is moved over an actor.

public void
exit(InputEvent event, float x, float y, int pointer, Actor toActor)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.exit.

Called any time the mouse cursor or a finger touch is moved out of an actor.

public int
public int
getPressedButton()

The button that initially pressed this button or -1 if the button is not pressed.

public int
getPressedPointer()

The pointer that initially pressed this button or -1 if the button is not pressed.

public int
getTapCount()

Returns the number of taps within the tap count interval for the most recent click event.

public float
public float
public float
public boolean
inTapSquare(float x, float y)

public boolean
inTapSquare()

Returns true if a touch is within the tap square.

public void
invalidateTapSquare()

The tap square will no longer be used for the current touch.

public boolean
isOver(Actor actor, float x, float y)

Returns true if the specified position is over the specified actor or within the tap square.

public boolean
isOver()

Returns true if the mouse or touch is over the actor or pressed and within the tap square.

public boolean
isPressed()

Returns true if a touch is over the actor or within the tap square.

public boolean
isVisualPressed()

Returns true if a touch is over the actor or within the tap square or has been very recently.

public void
setButton(int button)

Sets the button to listen for, all other buttons are ignored.

public void
setTapCount(int tapCount)

public void
setTapCountInterval(float
time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.
tapCountInterval
)

public void
setTapSquareSize(float halfTapSquareSize)

public void
setVisualPressed(boolean visualPressed)

If true, sets the visual pressed time to now.

public boolean
touchDown(InputEvent event, float x, float y, int pointer, int button)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchDown.

Called when a mouse button or a finger touch goes down on the actor.

public void
touchDragged(InputEvent event, float x, float y, int pointer)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchDragged.

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.

public void
touchUp(InputEvent event, float x, float y, int pointer, int button)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchUp.

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.

Inherited from com.badlogic.gdx.scenes.scene2d.InputListener:
handlekeyDownkeyTypedkeyUpmouseMovedscrolled

Field Detail

buttonback to summary
private int button
cancelledback to summary
private boolean cancelled
cancelledOverback to summary
private boolean cancelledOver
lastTapTimeback to summary
private long lastTapTime
overback to summary
private boolean over
pressedback to summary
private boolean pressed
pressedButtonback to summary
private int pressedButton
pressedPointerback to summary
private int pressedPointer
tapCountback to summary
private int tapCount
tapCountIntervalback to summary
private long tapCountInterval
tapSquareSizeback to summary
private float tapSquareSize
touchDownXback to summary
private float touchDownX
touchDownYback to summary
private float touchDownY
visualPressedDurationback to summary
public static float visualPressedDuration

Time in seconds isVisualPressed() reports true after a press resulting in a click is released.

visualPressedTimeback to summary
private long visualPressedTime

Constructor Detail

ClickListenerback to summary
public ClickListener()

Create a listener where clicked(InputEvent, float, float) is only called for left clicks.

See Also
ClickListener(int)
ClickListenerback to summary
public ClickListener(int button)
See Also
setButton(int)

Method Detail

cancelback to summary
public void cancel()

If a touch down is being monitored, the over state and drag and touch up events are ignored until the next touch up.

clickedback to summary
public void clicked(InputEvent event, float x, float y)
enterback to summary
public void enter(InputEvent event, float x, float y, int pointer, Actor fromActor)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.enter.

Doc from com.badlogic.gdx.scenes.scene2d.InputListener.enter.

Called any time the mouse cursor or a finger touch is moved over an actor. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).

exitback to summary
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.exit.

Doc from com.badlogic.gdx.scenes.scene2d.InputListener.exit.

Called any time the mouse cursor or a finger touch is moved out of an actor. On the desktop, this event occurs even when no mouse buttons are pressed (pointer will be -1).

getButtonback to summary
public int getButton()
See Also
setButton(int)
getPressedButtonback to summary
public int getPressedButton()

The button that initially pressed this button or -1 if the button is not pressed.

getPressedPointerback to summary
public int getPressedPointer()

The pointer that initially pressed this button or -1 if the button is not pressed.

getTapCountback to summary
public int getTapCount()

Returns the number of taps within the tap count interval for the most recent click event.

getTapSquareSizeback to summary
public float getTapSquareSize()
getTouchDownXback to summary
public float getTouchDownX()
getTouchDownYback to summary
public float getTouchDownY()
inTapSquareback to summary
public boolean inTapSquare(float x, float y)
inTapSquareback to summary
public boolean inTapSquare()

Returns true if a touch is within the tap square.

invalidateTapSquareback to summary
public void invalidateTapSquare()

The tap square will no longer be used for the current touch.

isOverback to summary
public boolean isOver(Actor actor, float x, float y)

Returns true if the specified position is over the specified actor or within the tap square.

isOverback to summary
public boolean isOver()

Returns true if the mouse or touch is over the actor or pressed and within the tap square.

isPressedback to summary
public boolean isPressed()

Returns true if a touch is over the actor or within the tap square.

isVisualPressedback to summary
public boolean isVisualPressed()

Returns true if a touch is over the actor or within the tap square or has been very recently. This allows the UI to show a press and release that was so fast it occurred within a single frame.

setButtonback to summary
public void setButton(int button)

Sets the button to listen for, all other buttons are ignored. Default is Buttons#LEFT. Use -1 for any button.

setTapCountback to summary
public void setTapCount(int tapCount)
setTapCountIntervalback to summary
public void setTapCountInterval(float tapCountInterval)
Parameters
tapCountInterval:float

time in seconds that must pass for two touch down/up sequences to be detected as consecutive taps.

setTapSquareSizeback to summary
public void setTapSquareSize(float halfTapSquareSize)
setVisualPressedback to summary
public void setVisualPressed(boolean visualPressed)

If true, sets the visual pressed time to now. If false, clears the visual pressed time.

touchDownback to summary
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchDown.

Doc from com.badlogic.gdx.scenes.scene2d.InputListener.touchDown.

Called when a mouse button or a finger touch goes down on the actor. If true is returned, this listener will have touch 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 is handled.

touchDraggedback to summary
public void touchDragged(InputEvent event, float x, float y, int pointer)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchDragged.

Doc from com.badlogic.gdx.scenes.scene2d.InputListener.touchDragged.

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. The touchDragged event is always handled.

touchUpback to summary
public void touchUp(InputEvent event, float x, float y, int pointer, int button)

Overrides com.badlogic.gdx.scenes.scene2d.InputListener.touchUp.

Doc from com.badlogic.gdx.scenes.scene2d.InputListener.touchUp.

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. The touchUp event is always handled.