InputMap

EntityInputMapBaseInputMapImplceramic.InputMap (Class)

A flexible input mapping system that allows binding physical inputs to logical actions.

InputMap provides a unified interface for mapping various input types (keyboard keys, gamepad buttons, mouse buttons, and analog axes) to game-specific actions defined by the type parameter T (typically an enum).

Features:

  • Bind multiple physical inputs to a single action
  • Support for keyboard (key codes and scan codes), mouse, and gamepad inputs
  • Convert digital inputs to analog axis values
  • Convert analog inputs to digital button presses
  • Track input states: pressed, just pressed, just released
  • Handle analog axis values for smooth input

Example usage:

enum Action {
    JUMP;
    MOVE_LEFT;
    MOVE_RIGHT;
    SHOOT;
    MOVE_X; // For analog movement
}

var inputMap = new InputMap<Action>();

// Bind keyboard keys
inputMap.bindKeyCode(JUMP, KeyCode.SPACE);
inputMap.bindKeyCode(MOVE_LEFT, KeyCode.A);
inputMap.bindKeyCode(MOVE_RIGHT, KeyCode.D);

// Bind gamepad
inputMap.bindGamepadButton(JUMP, GamepadButton.A);
inputMap.bindGamepadAxis(MOVE_X, GamepadAxis.LEFT_X);

// Convert digital to analog
inputMap.bindKeyCodeToAxis(MOVE_X, KeyCode.A, -1.0);
inputMap.bindKeyCodeToAxis(MOVE_X, KeyCode.D, 1.0);

// In update loop
if (inputMap.justPressed(JUMP)) {
    player.jump();
}
var moveX = inputMap.axisValue(MOVE_X);
player.velocity.x = moveX * speed;

Metadata

Name Parameters
:hxGen -
:build ceramic.macros.EntityMacro.buildForCompletion()
:autoBuild ceramic.macros.EntityMacro.buildForCompletion()
:build tracker.macros.EventsMacro.build()
:autoBuild tracker.macros.EventsMacro.build()