Package arc.scene.ui
Class Touchpad
java.lang.Object
arc.scene.Element
arc.scene.ui.Touchpad
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.ChangeEvent
is fired when the touchpad knob is moved. Cancelling the event will move the knob to where it was
previously.
-
Nested Class Summary
-
Field Summary
Fields inherited from class arc.scene.Element
color, cullable, fillParent, height, name, originX, originY, parent, parentAlpha, rotation, scaleX, scaleY, touchable, touchablility, translation, userObject, visibility, visible, width, x, y
-
Constructor Summary
ConstructorDescriptionTouchpad
(float deadzoneRadius) Touchpad
(float deadzoneRadius, Touchpad.TouchpadStyle style) -
Method Summary
Modifier and TypeMethodDescriptionvoid
draw()
Draws the element.float
Returns the x-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.float
Returns the y-position of the knob as a percentage from the center of the touchpad to the edge of the circular movement area.float
getKnobX()
Returns the x-position of the knob relative to the center of the widget.float
getKnobY()
Returns the y-position of the knob relative to the center of the widget.float
float
boolean
getStyle()
Returns the touchpad's style.hit
(float x, float y, boolean touchable) Returns the deepest actor that contains the specified point and istouchable
andvisible
, or null if no actor was hit.boolean
void
layout()
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsElement.invalidate()
on any each child whose width or height has changed, and callsElement.validate()
on each child.void
setDeadzone
(float deadzoneRadius) void
setResetOnTouchUp
(boolean reset) void
setStyle
(Touchpad.TouchpadStyle style) Methods inherited from class arc.scene.Element
act, actions, addAction, addCaptureListener, addListener, change, changed, clear, clearActions, clearListeners, clicked, clicked, clicked, clicked, clipBegin, clipBegin, clipEnd, dragged, exited, fire, fireClick, getActions, getCaptureListeners, getHeight, getListeners, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getRight, getRotation, getScene, getTop, getWidth, getX, getY, getZIndex, hasActions, hasKeyboard, hasMouse, hasParent, hasScroll, hovered, invalidate, invalidateHierarchy, isAscendantOf, isDescendantOf, isDescendantOf, isTouchable, keepInStage, keyDown, keyDown, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, needsLayout, notify, pack, parentToLocalCoordinates, released, remove, removeAction, removeCaptureListener, removeListener, requestKeyboard, requestScroll, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, scrolled, setBounds, setColor, setColor, setFillParent, setHeight, setLayoutEnabled, setOrigin, setOrigin, setPosition, setPosition, setRotation, setRotationOrigin, setScale, setScale, setScene, setSize, setSize, setTranslation, setWidth, setZIndex, sizeBy, sizeBy, sizeChanged, stageToLocalCoordinates, tapped, toBack, toFront, toString, touchable, update, updateVisibility, validate, visible
-
Constructor Details
-
Touchpad
public Touchpad(float deadzoneRadius) - Parameters:
deadzoneRadius
- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
Touchpad
- Parameters:
deadzoneRadius
- The distance in pixels from the center of the touchpad required for the knob to be moved.
-
-
Method Details
-
getStyle
Returns the touchpad's style. Modifying the returned style may not have an effect untilsetStyle(TouchpadStyle)
is called. -
setStyle
-
hit
Description copied from class:Element
Returns the deepest actor that contains the specified point and istouchable
andvisible
, 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.
-
layout
public void layout()Description copied from class:Element
Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, callsElement.invalidate()
on any each child whose width or height has changed, and callsElement.validate()
on each child. This method should almost never be called directly, insteadElement.validate()
should be used. -
draw
public void draw()Description copied from class:Element
Draws the element. Does nothing by default. -
getPrefWidth
public float getPrefWidth()- Overrides:
getPrefWidth
in classElement
-
getPrefHeight
public float getPrefHeight()- Overrides:
getPrefHeight
in classElement
-
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.
-