java.lang.Object GamePad
public class GamePad
A high-level wrapper to a controller. This is a singleton class that returns all of the controllers found connected to this machine.
Note that this is designed to work with DualShock Playstation-like controllers (but without rumble).
These are controllers with 4 action buttons, 6 L and R buttons (3 for left and 3 for right), 2 middle buttons (select and start), a d-pad (the direction buttons) and 2 analogue sticks.
Nested Class Summary | |
---|---|
static class |
GamePad.Axis
The different types of axis on the joypad. |
static class |
GamePad.Button
An enum of all of the different buttons most commonly supported. |
Method Summary | |
---|---|
Direction |
getAxis(GamePad.Axis axis)
This returns a Direction describing the current angle and strength of the Axis polled. |
static GamePad |
getGamePad()
This returns the first GamePad that this library finds connected to your PC. |
static GamePad |
getGamePad(int index)
For grabbing a specific gamepad that is connected to your PC. |
static GamePad[] |
getGamePads()
Returns all of the GamePads that this library can find connected to your PC. |
static int |
getNumGamePads()
|
boolean |
isAxisSupported(GamePad.Axis axis)
Checks if the given axis is supported or not. |
boolean |
isButtonSupported(GamePad.Button button)
Checks if the given button is supported on your gamepad, and so will work when pressed, or not. |
boolean |
isDown(GamePad.Button button)
Checks if the button given is pressed down or not. |
static void |
refreshGamePads()
Rescans the PC for all GamePads connected. |
void |
runConfigurePad()
Runs and shows a GamePad configuration GUI for setting gamepad mappings. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public Direction getAxis(GamePad.Axis axis)
This returns a Direction describing the current angle and strength of the Axis polled. This will return a Direction regardless of if the Axis is in use or not.
Axis which are not supported still return a Direction. But it will just never show any movement.
To tell if the Direction is or is not in use then you should check the strength of the Direction.
axis
- The Axis to poll.
public static GamePad getGamePad()
This returns the first GamePad that this library finds connected to your PC. If there is only one GamePad connected, then that is the one that is returned.
If no game pad is plugged in then this will throw an exception. This will always return the same first GamePad it has found.
java.lang.IllegalStateException
- if there is no real game pad found.public static GamePad getGamePad(int index)
For grabbing a specific gamepad that is connected to your PC.
The index given should be from 0 to the number of game pads on this machine, exclusive.
index
- The index of the GamePad to find.
public static GamePad[] getGamePads()
Returns all of the GamePads that this library can find connected to your PC.
If no pads are found then an empty array is returned.
public static int getNumGamePads()
public boolean isAxisSupported(GamePad.Axis axis)
Checks if the given axis is supported or not.
The
- Axis object to check.
public boolean isButtonSupported(GamePad.Button button)
Checks if the given button is supported on your gamepad, and so will work when pressed, or not.
public boolean isDown(GamePad.Button button)
Checks if the button given is pressed down or not. If the button is not supported then this will always fail silently and return false.
button
- The button to check.
public static void refreshGamePads()
Rescans the PC for all GamePads connected. Calling getGamePads() after this will return the latest number of pads connected to the machine.
public void runConfigurePad()
Runs and shows a GamePad configuration GUI for setting gamepad mappings.
This is what you can use for allowing users to reconfigure their gamepad within your scenario.