Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Single Axis Inputs in Virtual DPads #180

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ serde = {version = "1.0", features = ["derive"]}

[dev-dependencies]
bevy = {git = "https://github.com/bevyengine/bevy", default-features = false, features = ["bevy_gilrs", "bevy_sprite", "bevy_text", "bevy_ui", "bevy_render", "bevy_core_pipeline", "x11"]}
bevy_egui = { version="0.14", default-features = false }
# Uncomment once Bevy 0.8 is relese and bevy_egui supports it
#bevy_egui = "0.14.0"

[lib]
name = "leafwing_input_manager"
Expand Down
24 changes: 12 additions & 12 deletions examples/axis_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ fn spawn_player(mut commands: Commands) {
// Stores "which actions are currently activated"
action_state: ActionState::default(),
// Describes how to convert from player inputs into those actions
input_map: InputMap::new([
input_map: InputMap::default()
// Configure the left stick as a dual-axis
(DualAxis::left_stick(), Action::Move),
])
// Let's bind the right gamepad trigger to the throttle action
.insert(GamepadButtonType::RightTrigger2, Action::Throttle)
// And we'll use the right stick's x axis as a rudder control
.insert(
// This will trigger if the axis is moved 10% or more in either direction.
SingleAxis::symmetric(GamepadAxisType::RightStickX, 0.1),
Action::Rudder,
)
.build(),
.insert(DualAxis::left_stick(), Action::Move)
// Let's bind the right gamepad trigger to the throttle action
.insert(GamepadButtonType::RightTrigger2, Action::Throttle)
// And we'll use the right stick's x axis as a rudder control
.insert(
// This will trigger if the axis is moved 10% or more in either direction.
SingleAxis::symmetric(GamepadAxisType::RightStickX, 0.1),
Action::Rudder,
)
.build(),
});
}

// Query for the `ActionState` component in your game logic systems!
fn move_player(query: Query<&ActionState<Action>, With<Player>>) {
let action_state = query.single();

// Each action has a button-like state of its own that you can check
if action_state.pressed(Action::Move) {
// We're working with gamepads, so we want to defensively ensure that we're using the clamped values
Expand Down
Loading