[][src]Trait amethyst_input::BindingTypes

pub trait BindingTypes: Debug + Send + Sync + 'static {
    type Axis: Clone + Debug + Hash + Eq + Send + Sync + 'static;
    type Action: Clone + Debug + Hash + Eq + Send + Sync + 'static;
}

Define a set of types used for bindings configuration. Usually defaulted to StringBindings, which uses Strings.

By defining your own set of types (usually enums), you will be able to have compile-time guarantees while handling events, and you can also add additional context, for example player index in local multiplayer game.

Example configuration for local multiplayer driving game might look like this:

# use serde::{Serialize, Deserialize};
# use amethyst_input::{BindingTypes, Bindings};
type PlayerId = u8;

#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
enum AxisBinding {
    Throttle(PlayerId),
    Steering(PlayerId),
}

#[derive(Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
enum ActionBinding {
    UsePowerup(PlayerId),
}

#[derive(Debug)]
struct DriverBindingTypes;
impl BindingTypes for DriverBindingTypes {
    type Axis = AxisBinding;
    type Action = ActionBinding;
}

type GameBindings = Bindings<DriverBindingTypes>;

And the bindings.ron:

(
  axes: {
    Throttle(0): Emulated(pos: Key(W), neg: Key(S)),
    Steering(0): Emulated(pos: Key(D), neg: Key(A)),
    Throttle(1): Emulated(pos: Key(Up), neg: Key(Down)),
    Steering(1): Emulated(pos: Key(Right), neg: Key(Left)),
  },
  actions: {
    UsePowerup(0): [[Key(E)]],
    UsePowerup(1): [[Key(P)]],
  },
)

Associated Types

type Axis: Clone + Debug + Hash + Eq + Send + Sync + 'static

Type used for defining axis keys. Usually an enum or string.

type Action: Clone + Debug + Hash + Eq + Send + Sync + 'static

Type used for defining action keys. Usually an enum or string.

Loading content...

Implementors

impl BindingTypes for StringBindings[src]

type Axis = String

type Action = String

Loading content...