Class GamePad

java.lang.Object
  extended by GamePad

public class GamePad
extends java.lang.Object

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.

Author:
Joseph Lenton

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.
 
Field Summary
static int NO_ANGLE
          Methods that return an angle often also need to return that there is no angle at all.
 
Method Summary
 Direction getAxis(GamePad.Axis axis)
          The current direction of the given axis.
static GamePad getGamePad()
          If no game pad is plugged in then this will throw an exception.
static GamePad getGamePad(int index)
          The index given should be from 0 to the number of game pads on this machine, exclusive.
static GamePad[] getGamePads()
          If no pads are found then an empty array is returned.
static int getNumGamePads()
           
 boolean isAxisSupported(GamePad.Axis axis)
           
 boolean isButtonSupported(GamePad.Button button)
           
 boolean isDown(GamePad.Button button)
          The button given must already be supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_ANGLE

public static final int NO_ANGLE
Methods that return an angle often also need to return that there is no angle at all. When they do this they will return this value.

See Also:
Constant Field Values
Method Detail

getAxis

public Direction getAxis(GamePad.Axis axis)
The current direction of the given axis. This includes it's direction and it's strength. If the axis is deemed to be not pointing anywhere, then null is returned.

Returns:
A reading from the axis, or null if it is not in use.

getGamePad

public static GamePad getGamePad()
If no game pad is plugged in then this will throw an exception. This will always return the same first GamePad it has found.

Returns:
The first GamePad found.
Throws:
java.lang.IllegalStateException - if there is no real game pad found.

getGamePad

public static GamePad getGamePad(int index)
The index given should be from 0 to the number of game pads on this machine, exclusive.

Parameters:
index - The index of the GamePad to find.
Returns:
The GamePad stored against the given index.

getGamePads

public static GamePad[] getGamePads()
If no pads are found then an empty array is returned.

Returns:
An array containing all of the GamePads found connected to this machine.

getNumGamePads

public static int getNumGamePads()
Returns:
The number of game pads available on this PC, 0 for no pads.

isAxisSupported

public boolean isAxisSupported(GamePad.Axis axis)
Returns:
True if the given axis is available to be read on this GamePad.

isButtonSupported

public boolean isButtonSupported(GamePad.Button button)
Returns:
True if the given button enum is supported by this controller.

isDown

public boolean isDown(GamePad.Button button)
The button given must already be supported.

Parameters:
button - The button to check.
Returns:
True if the button with the given index is pressed, otherwise false.