Struct gamepads::Gamepads

source ·
pub struct Gamepads { /* private fields */ }
Expand description

Context for obtaining gamepad information.

Construct an instance using Gamepads::new.

On each tick, update gamepads state using Gamepads::poll().

Then use Gamepads::all() to list all connected gamepads, or Gamepads::get(gamepad_id) to get a gamepad by id.

Implementations§

source§

impl Gamepads

source

pub fn new() -> Self

Construct a new gamepads instance.

source

pub fn get(&self, gamepad_id: GamepadId) -> Option<Gamepad>

Get a gamepad by id, returning None if it is no longer connected.

The gamepad state obtained here will reflect the state the last time Gamepads::poll() was called.

source

pub fn all(&self) -> impl Iterator<Item = Gamepad>

Retrieve information about all connected gamepads.

The gamepad state obtained here will reflect the state the last time Gamepads::poll() was called.

source

pub fn rumble( &mut self, gamepad_id: GamepadId, duration_ms: u32, start_delay_ms: u32, strong_magnitude: f32, weak_magnitude: f32 )

Provide haptic feedback by rumbling the gamepad (if supported).

This is a “dual rumble”, where an eccentric rotating mass (ERM) vibration motor in each handle of the gamepad. Either motor is capable of vibrating the whole gamepad. The vibration effects created by each motor are unequal so that the effects of each can be combined to create more complex haptic effects.

Arguments
  • gamepad_id - ID of the gamepad to rumble
  • duration_ms - Duration of the rumble in milliseconds
  • start_delay_ms - Delay of the rumble in milliseconds
  • strong_magnitude - The vibration magnitude for the low frequency rumble in the range [0.0, 1.0]
  • weak_magnitude - The vibration magnitude for the high frequency rumble in the range [0.0, 1.0]
source

pub fn poll(&mut self)

Update gamepad state.

Should be called on each tick before reading gamepad state.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.