mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
b0058dc54b
# Objective Closes #16221. ## Solution - Make `Gamepad` fields public and remove delegates / getters. - Move `impl Into` to `Axis` methods (delegates for `Axis` used `impl Into` to allow passing both `GamepadAxis` and `GamepadButton`). - Improve docs. ## Testing - I run tests. Not sure if the migration guide is needed, since it's a feature from RC, but I wrote it just in case. --- ## Migration Guide - `Gamepad` fields are now public. - Instead of using `Gamepad` delegates like `Gamepad::just_pressed`, call these methods directly on the fields. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
30 lines
1,000 B
Rust
30 lines
1,000 B
Rust
//! Shows handling of gamepad input, connections, and disconnections.
|
|
|
|
use bevy::prelude::*;
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(Update, gamepad_system)
|
|
.run();
|
|
}
|
|
|
|
fn gamepad_system(gamepads: Query<(Entity, &Gamepad)>) {
|
|
for (entity, gamepad) in &gamepads {
|
|
if gamepad.digital.just_pressed(GamepadButton::South) {
|
|
info!("{:?} just pressed South", entity);
|
|
} else if gamepad.digital.just_released(GamepadButton::South) {
|
|
info!("{:?} just released South", entity);
|
|
}
|
|
|
|
let right_trigger = gamepad.analog.get(GamepadButton::RightTrigger2).unwrap();
|
|
if right_trigger.abs() > 0.01 {
|
|
info!("{:?} RightTrigger2 value is {}", entity, right_trigger);
|
|
}
|
|
|
|
let left_stick_x = gamepad.analog.get(GamepadAxis::LeftStickX).unwrap();
|
|
if left_stick_x.abs() > 0.01 {
|
|
info!("{:?} LeftStickX value is {}", entity, left_stick_x);
|
|
}
|
|
}
|
|
}
|