3 unstable releases
0.2.1 | Jul 31, 2020 |
---|---|
0.2.0 | Jul 28, 2020 |
0.1.0 | Jul 27, 2020 |
#5 in #gilrs
21KB
407 lines
bami
The basic amethyst input library. Offers simple utility for input with the amethyst crate.
Controller support can be added through the gilrs feature :
[dependencies.bami]
version = "0.2.0"
features = ["gilrs"]
This crate is a work in progress, some controller bindings may not yet be supported.
Setup :
use bami::BamiBundle;
let game_data = GameDataBuilder::default()
...
.with_bundle(BamiBundle::<StringBindings>::default())?
// ^------ Add this bundle AFTER the `InputBundle`
// Feel free to replace `StringBindings` with a custom type
...
Usage :
Feel free to replace StringBindings
with a custom type in your code!
use bami::{Input};
// Inside a system
type SystemData = Read<'s, Input<StringBindings>>;
fn run(&mut self, input: Self::SystemData) {
let action = String::from("jump");
// Only true the first frame of a same press
let pressed_this_frame =
input.actions.single_press(&action).is_down;
// `true` every frame the action is held
// Represents the raw input state.
let being_held_down: bool =
input.actions.status(&action).is_down;
let axis = String::from("horizontal");
// Axis value between [-1.0, 1.0].
let walk_speed: f32 =
input.axes.status(&axis).axis;
// Axes can also be used for menus with `single_press`.
// Every frame where the axis is not at 0.0 is considered
// a press. On the frames where `single_press` would
// return `is_down=false`, the axis value will also be 0.0
let menu_axis =
input.axes.single_press(&axis).axis;
if menu_axis > 0.0 {
// Pressed right
} else if menu_axis < 0.0 {
// Pressed left
}
}
Run tests:
cargo test --features amethyst/empty
Dependencies
~17–27MB
~419K SLoC