Gamepad
Overview
Turbo gamepad layouts are similar to a SNES controller. Gamepad controls for players 1 and 2 are automatically mapped to the keyboard:
Gamepad | Keyboard (P1) | Keyboard (P2) |
---|---|---|
Up | W or UpArrow | I |
Down | S or DownArrow | J |
Left | A or LeftArrow | K |
Right | D or RightArrow | L |
A | Z | M |
B | X | , |
X | C | . |
Y | V | / |
Start | Space | [ |
Select | Enter | ] |
API
gamepad::get
Gets the gamepad data for a player.
gamepad::get(gamepad_index: u32) -> Gamepad
Param | Type | Default | Description |
---|---|---|---|
gamepad_index | u32 | The gamepad input for. |
Usage
Basics
To retrieve the gamepad state of a player, use the gamepad
function.
// Get the gamepad state for player 1
let p1_gamepad = gamepad::get(0);
// Get the gamepad state for player 2
let p2_gamepad = gamepad::get(1);
Button Methods
To check the button states for players, utilize the following methods after obtaining the gamepad state using the gamepad
function:
let gp = gamepad::get(0);
if gp.a.just_pressed() {
// Fired at the instant the button/touch goes down
}
if gp.a.pressed() {
// True every frame the button is held down
}
if gp.a.just_released() {
// Fired at the moment the button is released
}
if gp.a.released() {
// True every frame the button is NOT held down
}