InputMapper
Index
Constructors
constructor
Parameters
inputs: InputsOptions
Returns InputMapper
Properties
publicinputs
Methods
execute
Executes the input map, called internally by Excalibur
Returns void
on
This allows you to map multiple inputs to specific commands! This is useful
The inputHandler should return a truthy value if you wish the commandHandler to fire.
Example:
const moveRight = (amount: number) => { actor.vel.x = 100 * amount } const moveLeft = (amount: number) => { actor.vel.x = -100 * amount } const moveUp = (amount: number) => { actor.vel.y = -100 * amount } const moveDown = (amount: number) => { actor.vel.y = 100 * amount } engine.inputMapper.on(({keyboard}) => keyboard.isHeld(ex.Keys.ArrowRight) ? 1 : 0, moveRight); engine.inputMapper.on(({gamepads}) => gamepads.at(0).isButtonPressed(ex.Buttons.DpadRight) ? 1 : 0, moveRight); engine.inputMapper.on(({gamepads}) => gamepads.at(0).getAxes(ex.Axes.LeftStickX) > 0 ? gamepads.at(0).getAxes(ex.Axes.LeftStickX) : 0, moveRight);
Type parameters
- TInputHandlerData
Parameters
inputHandler: (inputs: InputsOptions) => false | TInputHandlerData
commandHandler: (data: TInputHandlerData) => any
Returns void
This allows you to map multiple inputs to specific commands! This is especially useful when you need to allow multiple input sources to control a specific action.