Skip to content

Commit

Permalink
Added pressed state to input clear so it clears everything (bevyengin…
Browse files Browse the repository at this point in the history
…e#4410)

# Objective

Adds `pressed` state to Input::clear(). Fixes bevyengine#3383
  • Loading branch information
Troels Jessen authored and aevyrie committed Jun 7, 2022
1 parent a19c3e1 commit 44abb27
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/bevy_input/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ where
self.just_released.remove(&input);
}

/// Clear just pressed and just released information.
/// Clear pressed, just pressed and just released information.
pub fn clear(&mut self) {
self.just_pressed.clear();
self.just_released.clear();
self.pressed.clear();
}

/// List all inputs that are pressed.
Expand Down Expand Up @@ -166,16 +167,20 @@ mod test {
assert!(input.pressed(DummyInput::Input1));
assert!(input.pressed(DummyInput::Input2));

// Clear the `input`, removing just pressed and just released
// Clear the `input`, removing pressed, just pressed and just released
input.clear();

// Check if they're marked "just pressed"
assert!(!input.just_pressed(DummyInput::Input1));
assert!(!input.just_pressed(DummyInput::Input2));

// Check if they're marked as pressed
assert!(input.pressed(DummyInput::Input1));
assert!(input.pressed(DummyInput::Input2));
assert!(!input.pressed(DummyInput::Input1));
assert!(!input.pressed(DummyInput::Input2));

// Test pressing
input.press(DummyInput::Input1);
input.press(DummyInput::Input2);

// Release the inputs and check state

Expand Down

0 comments on commit 44abb27

Please sign in to comment.