Expand description
Input to Action Binding library for Bevy Game Engine.
§Features
- Maps Actions to input bindings
- Uses
bevy_inputinternally, supports Keyboard, Gamepad, and Mouse. - Can produce
Messagefor common input events. InputBindinglets you bind any axis or button to any axis or button like input.ActionBindinghas internal states to best represent button like behavior: JustPressed, Pressed, JustReleased, Released. Can also be used as digital (-1, 0, 1) axis.ValueBindingcan return a value (-1.0 to 1.0) from any axis or set of buttons. Can have a stack of generic functions that modify the output. Can be used as a button, by default it is assumed any non-zero value is pressed, but modifiers can enable you to control this behavior more finely.DualValueBindinginternally behaves as if it is just 2ValueBinding’s.
ButtonChord(multiple buttons at once) with configurable settings for resolving clashing inputs.ButtonCombo(multiple sequentially pressed buttons). Think GTA cheats but without incorrect buttons interrupting it.
§Usage
§Binding Types to be aware of
BevyInputKindwhich is and enum that is eitherBevyAxisKindorBevyButtonKind. Both inner types just resolve down to types frombevy_input.BevyAxisButtonthis converts an axis to a button.ButtonBindingthis whatinletuses as an actual binding to a button-like input. usesBevyButtonKindorBevyAxisButtonto detect presses.- Can be configured to be a
ButtonChord(multiple buttons that must be pressed all at once). - Can be configured to be a
ButtonCombo(multiple buttons pressed one after another).
- Can be configured to be a
AxisBindingthis whatinletuses as an actual binding to a axis-like input.
§Poll Only
see examples/poll-only.rs for code. below are the sets required for setups without using Message.
-
Create a list of input bindings to be used as a key to register bindings and retrieve values. This type MUST implement
Hash + PartialEq + Clone + Eq. -
Create a Bindings component and add it to your entity.
InputBindingsSimpleis just a type definition that fills in the message type with a placeholder for when you don’t want to deal with both generic types required forInputBindings.
-
Make a system that uses the values from bindings
-
Add
InputManagementPluginSimple<InputTypes>::default()and your system to your bevy app.
InputManagementPluginSimpleis just a type definition that fills in the message type with a placeholder type for when you don’t want to deal with both generic types required forInputManagementPlugin.
§Message Based
see examples/events.rs for code. below are the sets required for setups using Message triggered by
inputs.
-
Create a list of input bindings to be used as a key to register bindings and retrieve values. This type MUST implement
Hash + PartialEq + Eq + Clone -
Also create a type that implements
Message
You can make only 1 type that gets used for both if you want. This example separates them simply to show they can be separate types for cases where you are mixing message-based and polling-based bindings.
-
Create a Bindings component and add it to your entity.
-
Make a system that uses the values from bindings
you can also use polling in this system or other systems if you would like.
- Add
InputManagementPlugin<InputTypes, MessageType>::default()and your system to your bevy app.
§ClashSettings
If you like ButtonChords and have opinions about how inputs that clash should
behave: you can configure how that happens.
§Resource
You can spawn a ClashSettings resource (preferably on start up) that
all new InputHandler will use. The system that updates bindings
will automatically insert InputHandler on entities that have an
InputBindings attached to them, acting as a default.
§Component
When you insert ClashSettings as a component on an entity that also
has an attached InputBindings the settings will update and all current input states will reset. This
means you can allow player to configure this on a per-player basis.
Modules§
- axis
- Axis Like related types.
- button
- Button Like related types.
- manager
InputHandlerrelated types.
Structs§
- Input
Bindings - Map actions
Kto anInputBinding<T>whereTis aMessage. Also tracks the assignedGamepads. - Input
Management Plugin - Plugin required for
InputBindingsto function. - Simple
Message - Simple
Messagetype used byInputManagementPluginSimple.
Enums§
- Bevy
Axis Kind - A enum of all supported
bevy_inputtypes that can be used as axis-like bindings. - Bevy
Button Kind - A enum of all supported
bevy_inputtypes that can be used as button-like bindings. - Bevy
Input Kind - A enum of all supported
bevy_inputtypes that can be used as bindings. - Input
Binding - Generic binding for an input.
- Input
Value - A value from any input.
Traits§
- Bind
Event inlettrait for describingMessageevents, currently only requiresMessageto be auto-implemented. This type only exists to make it easier for me if a add requirements later.
Functions§
- pressed_
to_ value - Default logic for converting a button press to axis value.
- value_
to_ press - Default logic for converting a axis value to a button press.
Type Aliases§
- Input
Bindings Simple - Map actions
Kto anInputBinding<T>without a customMessagetype. Also tracks the assignedGamepads. - Input
Management Plugin Simple InputManagementPluginwhere theMessagetype is already filled with a placeholder for cases where the input manager will not be emitting input events forSimpleMessageis good enough for you.