libgdx API

com.badlogic.gdx.scenes.scene2d.ui
Class Touchpad

java.lang.Object
  extended by com.badlogic.gdx.scenes.scene2d.Actor
      extended by com.badlogic.gdx.scenes.scene2d.ui.Widget
          extended by 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.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 Class Summary
static class Touchpad.TouchpadStyle
          The style for a Touchpad.
 
Constructor Summary
Touchpad(float deadzoneRadius, Skin skin)
           
Touchpad(float deadzoneRadius, Skin skin, java.lang.String styleName)
           
Touchpad(float deadzoneRadius, Touchpad.TouchpadStyle style)
           
 
Method Summary
 void draw(SpriteBatch batch, float parentAlpha)
          If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.
 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.
 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.
 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 getPrefHeight()
           
 float getPrefWidth()
           
 Touchpad.TouchpadStyle getStyle()
          Returns the touchpad's style.
 Actor hit(float x, float y, boolean touchable)
          Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit.
 boolean isTouched()
           
 void layout()
          Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls Layout.invalidate() any each child whose width or height has changed, and calls Layout.validate() on each child.
 void setDeadzone(float deadzoneRadius)
           
 void setStyle(Touchpad.TouchpadStyle style)
           
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.ui.Widget
getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, invalidate, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, validate
 
Methods inherited from class com.badlogic.gdx.scenes.scene2d.Actor
act, addAction, addCaptureListener, addListener, clearActions, clipBegin, clipBegin, clipEnd, fire, getActions, getCaptureListeners, getColor, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getWidth, getX, getY, getZIndex, hasParent, isAscendantOf, isDescendantOf, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, notify, parentToLocalCoordinates, remove, removeAction, removeCaptureListener, removeListener, rotate, scale, scale, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOriginX, setOriginY, setParent, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setStage, setTouchable, setVisible, setWidth, setX, setY, setZIndex, size, size, stageToLocalCoordinates, toBack, toFront, toString, translate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 until setStyle(TouchpadStyle) is called.


hit

public Actor hit(float x,
                 float y,
                 boolean touchable)
Description copied from class: Actor
Returns the deepest actor that contains the specified point and is touchable and visible, 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 events. If this method returns null, touchDown will not occur.

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

Overrides:
hit in class Actor
touchable - If true, the hit detection will respect the touchability.
See Also:
Touchable

layout

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

Specified by:
layout in interface Layout
Overrides:
layout in class Widget

draw

public void draw(SpriteBatch batch,
                 float parentAlpha)
Description copied from class: Widget
If this method is overridden, the super method or Widget.validate() should be called to ensure the widget is laid out.

Overrides:
draw in class Widget
parentAlpha - Should be multipied with the actor's alpha, allowing a parent's alpha to affect all children.

getPrefWidth

public float getPrefWidth()
Specified by:
getPrefWidth in interface Layout
Overrides:
getPrefWidth in class Widget

getPrefHeight

public float getPrefHeight()
Specified by:
getPrefHeight in interface Layout
Overrides:
getPrefHeight in class Widget

isTouched

public boolean isTouched()

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.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)