Class Touchpad
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.Actor
-
- com.badlogic.gdx.scenes.scene2d.ui.Widget
-
- com.badlogic.gdx.scenes.scene2d.ui.Touchpad
-
- All Implemented Interfaces:
Layout
public class Touchpad extends Widget
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.
ChangeListener.ChangeEventis fired when the touchpad knob is moved. Cancelling the event will move the knob to where it was previously.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTouchpad.TouchpadStyleThe style for aTouchpad.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddraw(Batch batch, float parentAlpha)If this method is overridden, the super method orWidget.validate()should be called to ensure the widget is laid out.floatgetKnobPercentX()Returns the x-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.floatgetKnobPercentY()Returns the y-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.floatgetKnobX()Returns the x-position of the knob relative to the center of the widget.floatgetKnobY()Returns the y-position of the knob relative to the center of the widget.floatgetPrefHeight()floatgetPrefWidth()booleangetResetOnTouchUp()Touchpad.TouchpadStylegetStyle()Returns the touchpad's style.Actorhit(float x, float y, boolean touchable)booleanisTouched()voidlayout()Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()on any each child whose width or height has changed, and callsLayout.validate()on each child.voidsetDeadzone(float deadzoneRadius)voidsetResetOnTouchUp(boolean reset)voidsetStyle(Touchpad.TouchpadStyle style)-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validate
-
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, ancestorsVisible, ascendantsVisible, clear, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, debug, drawDebug, drawDebugBounds, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasKeyboardFocus, hasParent, hasScrollFocus, isAscendantOf, isDescendantOf, isTouchable, isTouchFocusListener, isTouchFocusTarget, isVisible, localToActorCoordinates, localToAscendantCoordinates, localToParentCoordinates, localToScreenCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, scaleChanged, screenToLocalCoordinates, setBounds, setColor, setColor, setDebug, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setUserObject, setVisible, setWidth, setX, setX, setY, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFront, toString
-
-
-
-
Constructor Detail
-
Touchpad
public Touchpad(float deadzoneRadius, Skin skin)- Parameters:
deadzoneRadius- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
Touchpad
public Touchpad(float deadzoneRadius, Skin skin, java.lang.String styleName)- Parameters:
deadzoneRadius- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
Touchpad
public Touchpad(float deadzoneRadius, Touchpad.TouchpadStyle style)- Parameters:
deadzoneRadius- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
-
Method Detail
-
setStyle
public void setStyle(Touchpad.TouchpadStyle style)
-
getStyle
public Touchpad.TouchpadStyle getStyle()
Returns the touchpad's style. Modifying the returned style may not have an effect untilsetStyle(TouchpadStyle)is called.
-
hit
public Actor hit(float x, float y, boolean touchable)
Description copied from class:ActorReturns the deepestvisible(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.
- Overrides:
hitin classActortouchable- If true, hit detection will respect thetouchability.- See Also:
Touchable
-
layout
public void layout()
Description copied from interface:LayoutComputes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsLayout.invalidate()on any each child whose width or height has changed, and callsLayout.validate()on each child. This method should almost never be called directly, insteadLayout.validate()should be used.
-
draw
public void draw(Batch batch, float parentAlpha)
Description copied from class:WidgetIf this method is overridden, the super method orWidget.validate()should be called to ensure the widget is laid out.
-
getPrefWidth
public float getPrefWidth()
- Specified by:
getPrefWidthin interfaceLayout- Overrides:
getPrefWidthin classWidget
-
getPrefHeight
public float getPrefHeight()
- Specified by:
getPrefHeightin interfaceLayout- Overrides:
getPrefHeightin classWidget
-
isTouched
public boolean isTouched()
-
getResetOnTouchUp
public boolean getResetOnTouchUp()
-
setResetOnTouchUp
public void setResetOnTouchUp(boolean reset)
- Parameters:
reset- Whether to reset the knob to the center on touch up.
-
setDeadzone
public void setDeadzone(float deadzoneRadius)
- Parameters:
deadzoneRadius- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
getKnobX
public float getKnobX()
Returns the x-position of the knob relative to the center of the widget. The positive direction is right.
-
getKnobY
public float getKnobY()
Returns the y-position of the knob relative to the center of the widget. The positive direction is up.
-
getKnobPercentX
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.
-
getKnobPercentY
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.
-
-