pub struct InputAction {
pub name: String,
pub keys: Vec<KeyCode>,
pub mouse_buttons: Vec<MouseButton>,
pub positive_axis: Vec<(u32, f32)>,
pub negative_axis: Vec<(u32, f32)>,
pub gamepad_buttons: Vec<u32>,
}Expand description
A named input action that can be bound to multiple keys/buttons.
§Example
let mut jump = InputAction::new("jump");
jump.bind_key(KeyCode::Space);
jump.bind_key(KeyCode::Up);
jump.bind_mouse(MouseButton::Left);
// In update:
if jump.is_pressed(&ctx.input) { player.jump(); }Fields§
§name: StringHuman-readable name.
keys: Vec<KeyCode>Bound keyboard keys.
Bound mouse buttons.
positive_axis: Vec<(u32, f32)>Positive gamepad axis + threshold (axis_index, threshold).
negative_axis: Vec<(u32, f32)>Negative gamepad axis + threshold.
Gamepad buttons.
Implementations§
Source§impl InputAction
impl InputAction
Sourcepub fn bind_mouse(&mut self, button: MouseButton) -> &mut Self
pub fn bind_mouse(&mut self, button: MouseButton) -> &mut Self
Bind a mouse button to this action.
Sourcepub fn is_down(&self, input: &InputState) -> bool
pub fn is_down(&self, input: &InputState) -> bool
Check if this action is currently active (held).
Sourcepub fn is_pressed(&self, input: &InputState) -> bool
pub fn is_pressed(&self, input: &InputState) -> bool
Check if this action was just activated (pressed edge).
Trait Implementations§
Source§impl Clone for InputAction
impl Clone for InputAction
Source§fn clone(&self) -> InputAction
fn clone(&self) -> InputAction
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for InputAction
impl RefUnwindSafe for InputAction
impl Send for InputAction
impl Sync for InputAction
impl Unpin for InputAction
impl UnsafeUnpin for InputAction
impl UnwindSafe for InputAction
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more