mirror of
https://github.com/bevyengine/bevy
synced 2025-02-27 21:07:17 +00:00
# Objective - The current `EventReader::iter` has been determined to cause confusion among new Bevy users. It was suggested by @JoJoJet to rename the method to better clarify its usage. - Solves #9624 ## Solution - Rename `EventReader::iter` to `EventReader::read`. - Rename `EventReader::iter_with_id` to `EventReader::read_with_id`. - Rename `ManualEventReader::iter` to `ManualEventReader::read`. - Rename `ManualEventReader::iter_with_id` to `ManualEventReader::read_with_id`. --- ## Changelog - `EventReader::iter` has been renamed to `EventReader::read`. - `EventReader::iter_with_id` has been renamed to `EventReader::read_with_id`. - `ManualEventReader::iter` has been renamed to `ManualEventReader::read`. - `ManualEventReader::iter_with_id` has been renamed to `ManualEventReader::read_with_id`. - Deprecated `EventReader::iter` - Deprecated `EventReader::iter_with_id` - Deprecated `ManualEventReader::iter` - Deprecated `ManualEventReader::iter_with_id` ## Migration Guide - Existing usages of `EventReader::iter` and `EventReader::iter_with_id` will have to be changed to `EventReader::read` and `EventReader::read_with_id` respectively. - Existing usages of `ManualEventReader::iter` and `ManualEventReader::iter_with_id` will have to be changed to `ManualEventReader::read` and `ManualEventReader::read_with_id` respectively.
63 lines
2.5 KiB
Rust
63 lines
2.5 KiB
Rust
//! Iterates and prints gamepad input and connection events.
|
|
|
|
use bevy::{
|
|
input::gamepad::{
|
|
GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadButtonInput,
|
|
GamepadConnectionEvent, GamepadEvent,
|
|
},
|
|
prelude::*,
|
|
};
|
|
|
|
fn main() {
|
|
App::new()
|
|
.add_plugins(DefaultPlugins)
|
|
.add_systems(Update, (gamepad_events, gamepad_ordered_events))
|
|
.run();
|
|
}
|
|
|
|
fn gamepad_events(
|
|
mut connection_events: EventReader<GamepadConnectionEvent>,
|
|
mut axis_changed_events: EventReader<GamepadAxisChangedEvent>,
|
|
// Handles the continuous measure of how far a button has been pressed down, as measured
|
|
// by `Axis<GamepadButton>`. Whenever that value changes, this event is emitted.
|
|
mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
|
|
// Handles the boolean measure of whether a button is considered pressed or unpressed, as
|
|
// defined by the thresholds in `GamepadSettings::button_settings` and measured by
|
|
// `Input<GamepadButton>`. When the threshold is crossed and the button state changes,
|
|
// this event is emmitted.
|
|
mut button_input_events: EventReader<GamepadButtonInput>,
|
|
) {
|
|
for connection_event in connection_events.read() {
|
|
info!("{:?}", connection_event);
|
|
}
|
|
for axis_changed_event in axis_changed_events.read() {
|
|
info!(
|
|
"{:?} of {:?} is changed to {}",
|
|
axis_changed_event.axis_type, axis_changed_event.gamepad, axis_changed_event.value
|
|
);
|
|
}
|
|
for button_changed_event in button_changed_events.read() {
|
|
info!(
|
|
"{:?} of {:?} is changed to {}",
|
|
button_changed_event.button_type,
|
|
button_changed_event.gamepad,
|
|
button_changed_event.value
|
|
);
|
|
}
|
|
for button_input_event in button_input_events.read() {
|
|
info!("{:?}", button_input_event);
|
|
}
|
|
}
|
|
|
|
// If you require in-frame relative event ordering, you can also read the `Gamepad` event
|
|
// stream directly. For standard use-cases, reading the events individually or using the
|
|
// `Input<T>` or `Axis<T>` resources is preferable.
|
|
fn gamepad_ordered_events(mut gamepad_events: EventReader<GamepadEvent>) {
|
|
for gamepad_event in gamepad_events.read() {
|
|
match gamepad_event {
|
|
GamepadEvent::Connection(connection_event) => info!("{:?}", connection_event),
|
|
GamepadEvent::Button(button_event) => info!("{:?}", button_event),
|
|
GamepadEvent::Axis(axis_event) => info!("{:?}", axis_event),
|
|
}
|
|
}
|
|
}
|