#include <Gamepad.h>
Public Types | |
enum | GamepadEvent { CONNECTED_EVENT, DISCONNECTED_EVENT } |
enum | ButtonMapping { BUTTON_A, BUTTON_B, BUTTON_X, BUTTON_Y, BUTTON_L1, BUTTON_L2, BUTTON_L3, BUTTON_R1, BUTTON_R2, BUTTON_R3, BUTTON_UP, BUTTON_DOWN, BUTTON_LEFT, BUTTON_RIGHT, BUTTON_MENU1, BUTTON_MENU2, BUTTON_MENU3 } |
Public Member Functions | |
unsigned int | getButtonCount () const |
bool | isButtonDown (ButtonMapping button) const |
unsigned int | getJoystickCount () const |
void | getJoystickValues (unsigned int joystickId, Vector2 *outValues) const |
unsigned int | getTriggerCount () const |
float | getTriggerValue (unsigned int triggerId) const |
const char * | getName () const |
bool | isVirtual () const |
Form * | getForm () const |
void | update (float elapsedTime) |
void | draw () |
Defines a gamepad interface for handling input from joysticks and buttons.
A gamepad can be either physical or virtual. Most platform support up to 4 gamepad controllers connected simulataneously.
Gamepad buttons.
Gamepad events.
void gameplay::Gamepad::draw | ( | ) |
Draws the gamepad if it is based on a form and if the form is enabled.
unsigned int gameplay::Gamepad::getButtonCount | ( | ) | const |
Gets the number of buttons on this gamepad.
Form* gameplay::Gamepad::getForm | ( | ) | const |
unsigned int gameplay::Gamepad::getJoystickCount | ( | ) | const |
Gets the number of joysticks on the gamepad.
void gameplay::Gamepad::getJoystickValues | ( | unsigned int | joystickId, |
Vector2 * | outValues | ||
) | const |
Returns the specified joystick's value as a Vector2.
joystickId | The index of the joystick to get the value for. |
outValues | The current x-axis and y-axis values of the joystick. |
const char* gameplay::Gamepad::getName | ( | ) | const |
Get this gamepad's device/product name.
unsigned int gameplay::Gamepad::getTriggerCount | ( | ) | const |
Returns the number of analog triggers (as opposed to digital shoulder buttons) on this gamepad.
float gameplay::Gamepad::getTriggerValue | ( | unsigned int | triggerId | ) | const |
Returns the value of an analog trigger on this gamepad. This value will be a number between 0 and 1, where 0 means the trigger is in its resting (unpressed) state and 1 means the trigger has been completely pressed down.
triggerId | The trigger to query. |
bool gameplay::Gamepad::isButtonDown | ( | ButtonMapping | button | ) | const |
Gets whether the given button is currently pressed down.
button | The enum of the button on the gamepad to get the state for. |
bool gameplay::Gamepad::isVirtual | ( | ) | const |
Returns whether the gamepad is currently represented with a UI form or not.
void gameplay::Gamepad::update | ( | float | elapsedTime | ) |
Updates the gamepad's state. For a virtual gamepad, this results in calling update() on the gamepad's form. For physical gamepads, this polls the gamepad's state at the platform level. Either way, this should be called once a frame before getting and using a gamepad's current state.
elapsedTime | The elapsed game time. |