Skip to main content

InputMapper

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.

Index

Constructors

Properties

Methods

Constructors

constructor

Properties

publicinputs

Methods

execute

  • execute(): void
  • Executes the input map, called internally by Excalibur


    Returns void

on

  • on<TInputHandlerData>(inputHandler: (inputs: InputsOptions) => false | TInputHandlerData, commandHandler: (data: TInputHandlerData) => any): void
  • 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