Top Description Fields Methods
com.badlogic.gdx.controllers

public Interface Controller

Known Direct Implementers
com.badlogic.gdx.controllers.AbstractController

Represents a connected controller. Provides methods to query the state of buttons, axes and more information on the controller. Multiple ControllerListener instances can be registered with the Controller to receive events in case the controller's state changes. Listeners will be invoked on the rendering thread.
Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
public static final int
PLAYER_IDX_UNSET

returned by getPlayerIndex() if no player index was set or feature is not supported

Method Summary

Modifier and TypeMethod and Description
public void
public void
cancelVibration()

Cancel any running vibration.

public boolean

Returns:

whether the connected controller or the current controller implementation can rumble. Note that this is no guarantee that the connected controller itself can vibrate.
canVibrate
()

public float

Returns:

the value of the axis, between -1 and 1
getAxis
(int axisCode)

public int

Returns:

number of axis of this controller. Axis indices start at 0, so the maximum axis index is one under this value.
getAxisCount
()

public boolean

Returns:

whether the button is pressed.
getButton
(int buttonCode)

public ControllerMapping

Returns:

button and axis mapping for this controller (or platform). The connected controller might not support all features.
getMapping
()

public int

Returns:

the maximum button index code that can be queried
getMaxButtonIndex
()

public int

Returns:

the minimum button index code that can be queried
getMinButtonIndex
()

public String

Returns:

the device name
getName
()

public int

Returns:

0-based player index of this controller, or PLAYER_IDX_UNSET if none is set
getPlayerIndex
()

public ControllerPowerLevel

Returns:

value of enum ControllerPowerLevel indicating battery state of the connected controller, or ControllerPowerLevel#POWER_UNKNOWN if information is not present
getPowerLevel
()

public String

Returns:

unique ID to recognize this controller if more than one of the same controller models are connected. Use this to map a controller to a player, but do not use it to save a button mapping.
getUniqueId
()

public boolean

Returns:

true when this Controller is still connected, false if it already disconnected
isConnected
()

public boolean

Returns:

if the controller is currently rumbling
isVibrating
()

public void
public void
setPlayerIndex(int
0 typically 0 to 3 for player indices, and PLAYER_IDX_UNSET for unset
index
)

Sets the player index of this controller.

public void
startVibration(int
duration, in milliseconds
duration
,
float
value between 0f and 1f
strength
)

Starts vibrating this controller, if possible.

public boolean

Returns:

whether the connected controller (or the implementation) can return and set the current player index
supportsPlayerIndex
()

Field Detail

PLAYER_IDX_UNSETback to summary
public static final int PLAYER_IDX_UNSET

returned by getPlayerIndex() if no player index was set or feature is not supported

Method Detail

addListenerback to summary
public void addListener(ControllerListener listener)

Adds a new ControllerListener to this Controller. The listener will receive calls in case the state of the controller changes. The listener will be invoked on the rendering thread.

cancelVibrationback to summary
public void cancelVibration()

Cancel any running vibration. May not be supported by implementations

canVibrateback to summary
public boolean canVibrate()
Returns:boolean

whether the connected controller or the current controller implementation can rumble. Note that this is no guarantee that the connected controller itself can vibrate.

getAxisback to summary
public float getAxis(int axisCode)
Returns:float

the value of the axis, between -1 and 1

getAxisCountback to summary
public int getAxisCount()
Returns:int

number of axis of this controller. Axis indices start at 0, so the maximum axis index is one under this value.

getButtonback to summary
public boolean getButton(int buttonCode)
Returns:boolean

whether the button is pressed.

getMappingback to summary
public ControllerMapping getMapping()
Returns:ControllerMapping

button and axis mapping for this controller (or platform). The connected controller might not support all features.

getMaxButtonIndexback to summary
public int getMaxButtonIndex()
Returns:int

the maximum button index code that can be queried

getMinButtonIndexback to summary
public int getMinButtonIndex()
Returns:int

the minimum button index code that can be queried

getNameback to summary
public String getName()
Returns:String

the device name

getPlayerIndexback to summary
public int getPlayerIndex()
Returns:int

0-based player index of this controller, or PLAYER_IDX_UNSET if none is set

getPowerLevelback to summary
public ControllerPowerLevel getPowerLevel()
Returns:ControllerPowerLevel

value of enum ControllerPowerLevel indicating battery state of the connected controller, or ControllerPowerLevel#POWER_UNKNOWN if information is not present

getUniqueIdback to summary
public String getUniqueId()
Returns:String

unique ID to recognize this controller if more than one of the same controller models are connected. Use this to map a controller to a player, but do not use it to save a button mapping.

isConnectedback to summary
public boolean isConnected()
Returns:boolean

true when this Controller is still connected, false if it already disconnected

isVibratingback to summary
public boolean isVibrating()
Returns:boolean

if the controller is currently rumbling

removeListenerback to summary
public void removeListener(ControllerListener listener)

Removes the given ControllerListener

setPlayerIndexback to summary
public void setPlayerIndex(int index)

Sets the player index of this controller. Please note that this does not always set indication lights of controllers, it is just an internal representation on some platforms

Parameters
index:int

0 typically 0 to 3 for player indices, and PLAYER_IDX_UNSET for unset

startVibrationback to summary
public void startVibration(int duration, float strength)

Starts vibrating this controller, if possible.

Parameters
duration:int

duration, in milliseconds

strength:float

value between 0f and 1f

supportsPlayerIndexback to summary
public boolean supportsPlayerIndex()
Returns:boolean

whether the connected controller (or the implementation) can return and set the current player index