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

public Class Touchpad

extends Widget
implements Styleable<Touchpad.TouchpadStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable
Imports
com.badlogic.gdx.graphics.Color, com.badlogic.gdx.graphics.g2d.Batch, com.badlogic.gdx.math.Circle, .Vector2, com.badlogic.gdx.scenes.scene2d.Actor, .InputEvent, .InputListener, .Touchable, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent, .Drawable, com.badlogic.gdx.utils.Null

An on-screen joystick. The movement area of the joystick is circular, centered on the touchpad, and its size determined by the smaller touchpad dimension.

The preferred size of the touchpad is determined by the background.

ChangeEvent is fired when the touchpad knob is moved. Cancelling the event will move the knob to where it was previously.

Author
Josh Street

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final Circle
private float
private final Circle
private final Vector2
private final Vector2
pack-priv boolean
private Touchpad.TouchpadStyle
private final Circle
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
Touchpad(float
The distance in pixels from the center of the touchpad required for the knob to be moved.
deadzoneRadius
,
Skin skin)

public
Touchpad(float
The distance in pixels from the center of the touchpad required for the knob to be moved.
deadzoneRadius
,
Skin skin, String styleName)

public
Touchpad(float
The distance in pixels from the center of the touchpad required for the knob to be moved.
deadzoneRadius
,
Touchpad.TouchpadStyle style)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
calculatePositionAndValue(float x, float y, boolean isTouchUp)

public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

public float
getKnobPercentX()

Returns the x-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.

public float
getKnobPercentY()

Returns the y-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.

public float
getKnobX()

Returns the x-position of the knob relative to the center of the widget.

public float
getKnobY()

Returns the y-position of the knob relative to the center of the widget.

public float
public float
public boolean
public Touchpad.TouchpadStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the touchpad's style.

public Actor
hit(float x, float y, boolean touchable)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.hit.

Returns the deepest visible (and optionally, touchable) actor that contains the specified point, or null if no actor was hit.

public boolean
public void
layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child.

public void
setDeadzone(float
The distance in pixels from the center of the touchpad required for the knob to be moved.
deadzoneRadius
)

public void
setResetOnTouchUp(boolean
Whether to reset the knob to the center on touch up.
reset
)

public void
setStyle(Touchpad.TouchpadStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Widget:
getMaxHeightgetMaxWidthgetMinHeightgetMinWidthinvalidateinvalidateHierarchyneedsLayoutpacksetFillParentsetLayoutEnabledsizeChangedvalidate

Field Detail

deadzoneBoundsback to summary
private final Circle deadzoneBounds
deadzoneRadiusback to summary
private float deadzoneRadius
knobBoundsback to summary
private final Circle knobBounds
knobPercentback to summary
private final Vector2 knobPercent
knobPositionback to summary
private final Vector2 knobPosition
resetOnTouchUpback to summary
pack-priv boolean resetOnTouchUp
styleback to summary
private Touchpad.TouchpadStyle style
touchBoundsback to summary
private final Circle touchBounds
touchedback to summary
pack-priv boolean touched

Constructor Detail

Touchpadback to summary
public Touchpad(float deadzoneRadius, Skin skin)
Parameters
deadzoneRadius:float

The distance in pixels from the center of the touchpad required for the knob to be moved.

Touchpadback to summary
public Touchpad(float deadzoneRadius, Skin skin, String styleName)
Parameters
deadzoneRadius:float

The distance in pixels from the center of the touchpad required for the knob to be moved.

Touchpadback to summary
public Touchpad(float deadzoneRadius, Touchpad.TouchpadStyle style)
Parameters
deadzoneRadius:float

The distance in pixels from the center of the touchpad required for the knob to be moved.

Method Detail

calculatePositionAndValueback to summary
pack-priv void calculatePositionAndValue(float x, float y, boolean isTouchUp)
drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Widget.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget is laid out.

getKnobPercentXback to summary
public float getKnobPercentX()

Returns the x-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area. The positive direction is right.

getKnobPercentYback to summary
public float getKnobPercentY()

Returns the y-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area. The positive direction is up.

getKnobXback to summary
public float getKnobX()

Returns the x-position of the knob relative to the center of the widget. The positive direction is right.

getKnobYback to summary
public float getKnobY()

Returns the y-position of the knob relative to the center of the widget. The positive direction is up.

getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getResetOnTouchUpback to summary
public boolean getResetOnTouchUp()
getStyleback to summary
public Touchpad.TouchpadStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the touchpad's style. Modifying the returned style may not have an effect until setStyle(TouchpadStyle) is called.

hitback to summary
public Actor hit(float x, float y, boolean touchable)

Overrides com.badlogic.gdx.scenes.scene2d.Actor.hit.

Doc from com.badlogic.gdx.scenes.scene2d.Actor.hit.

Returns the deepest visible (and optionally, touchable) actor that contains the specified point, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).

This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.

The default implementation returns this actor if the point is within this actor's bounds and this actor is visible.

isTouchedback to summary
public boolean isTouched()
layoutback to summary
public void layout()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Widget.layout.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Doc from com.badlogic.gdx.scenes.scene2d.utils.Layout.layout.

Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child. This method should almost never be called directly, instead validate() should be used.

setDeadzoneback to summary
public void setDeadzone(float deadzoneRadius)
Parameters
deadzoneRadius:float

The distance in pixels from the center of the touchpad required for the knob to be moved.

setResetOnTouchUpback to summary
public void setResetOnTouchUp(boolean reset)
Parameters
reset:boolean

Whether to reset the knob to the center on touch up.

setStyleback to summary
public void setStyle(Touchpad.TouchpadStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class Touchpad.TouchpadStyle

extends Object
Class Inheritance

The style for a Touchpad.
Author
Josh Street

Field Summary

Modifier and TypeField and Description
public Drawable
background

Stretched in both directions.

public Drawable

Constructor Summary

AccessConstructor and Description
public
public
TouchpadStyle(Drawable background, Drawable knob)

public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backgroundback to summary
public Drawable background

Stretched in both directions.

Annotations
@Null
knobback to summary
public Drawable knob
Annotations
@Null

Constructor Detail

TouchpadStyleback to summary
public TouchpadStyle()
TouchpadStyleback to summary
public TouchpadStyle(Drawable background, Drawable knob)
TouchpadStyleback to summary
public TouchpadStyle(Touchpad.TouchpadStyle style)