Gamepad
Gamepad
- vendor_id : core::option::Option
- product_id : core::option::Option
- digital : bevy_input::button_input::ButtonInput<bevy_input::gamepad::GamepadButton>
- analog : bevy_input::axis::Axis<bevy_input::gamepad::GamepadInput>
Description
Stores a connected gamepad's metadata such as the name and its [
GamepadButton
] and [GamepadAxis
].An entity with this component is spawned automatically after [
GamepadConnectionEvent
] and updated by [gamepad_event_processing_system
].See also [
GamepadSettings
] for configuration.Examples
# use bevy_input::gamepad::{Gamepad, GamepadAxis, GamepadButton}; # use bevy_ecs::system::Query; # use bevy_core::Name; # fn gamepad_usage_system(gamepads: Query<(&Name, &Gamepad)>) { for (name, gamepad) in &gamepads { println!("{name}"); if gamepad.just_pressed(GamepadButton::North) { println!("{} just pressed North", name) } if let Some(left_stick_x) = gamepad.get(GamepadAxis::LeftStickX) { println!("left stick X: {}", left_stick_x) } } }
Functions
Function | Summary |
---|---|
dpad(_self) | Returns the directional pad as a [`Vec2`] |
just_pressed(_self, button_type) | Returns `true` if the [`GamepadButton`] has been pressed during the current frame. Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] |
just_released(_self, button_type) | Returns `true` if the [`GamepadButton`] has been released during the current frame. Note: This function does not imply information regarding the current state of [`ButtonInput::pressed`] |
left_stick(_self) | Returns the left stick as a [`Vec2`] |
pressed(_self, button_type) | Returns `true` if the [`GamepadButton`] has been pressed. |
product_id(_self) | Returns the USB product ID as assigned by the [vendor], if available. [vendor]: Self::vendor_id |
right_stick(_self) | Returns the right stick as a [`Vec2`] |
vendor_id(_self) | Returns the USB vendor ID as assigned by the USB-IF, if available. |