class Eagle::Input::Gamepad

Overview

A connected game controller. Get one with Input.gamepad or iterate Input.gamepads.

Stick values have a deadzone applied, so a resting stick reads exactly 0. Most games use actions instead, but direct access is handy for twin-stick controls.

if pad = Input.gamepad
  aim = pad.right_stick
  pad.rumble(0.3, 0.6, 150) if pad.pressed?(GamepadButton::RightShoulder)
end

Defined in:

eagle/input/input.cr

Instance Method Summary

Instance Method Detail

def axis(a : GamepadAxis) : Float32 #

An axis value after the deadzone: -1 to 1 for sticks, 0 to 1 for triggers.


def deadzone : Float32 #

Stick values smaller than this read as 0. Raise it for worn sticks that drift.


def deadzone=(deadzone : Float32) #

Stick values smaller than this read as 0. Raise it for worn sticks that drift.


def down?(b : GamepadButton) : Bool #

True while b is held.


def id : Int32 #

The controller's id, as reported in gamepad events.


def left_stick : Vec2 #

The left stick as a vector. Up is negative y, matching screen space.


def name : String #

The controller's product name, such as "Xbox Wireless Controller".


def pressed?(b : GamepadButton) : Bool #

True on the frame b went down.


def raw_axis(a : GamepadAxis) : Float32 #

An axis value without the deadzone.


def released?(b : GamepadButton) : Bool #

True on the frame b went up.


def right_stick : Vec2 #

The right stick as a vector.


def rumble(low : Number = 0.5, high : Number = 0.5, ms : Int = 200) : Nil #

Vibrates the controller. low and high are motor strengths from 0 to 1.