Skip to content

Gamepad

Overview

Turbo gamepad layouts are similar to a SNES controller. Gamepad controls for players 1 and 2 are automatically mapped to the keyboard:

GamepadKeyboard (P1)Keyboard (P2)
UpW or UpArrowI
DownS or DownArrowJ
LeftA or LeftArrowK
RightD or RightArrowL
AZM
BX,
XC.
YV/
StartSpace[
SelectEnter]

API

gamepad::get

Gets the gamepad data for a player.

gamepad::get(gamepad_index: u32) -> Gamepad
ParamTypeDefaultDescription
gamepad_indexu32The 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
}