InputHandler

A utility class that provides a quick user-input handling functionality. It supports mouse interactions with world items, with default mouse-particle interactions baked in. Moreover, it also has key-event listening (can be on a focusable element, or the whole window). Lastly, it can handle simultaneous mouse-key press combinations.

Note: This will only work with an HTML canvas element in the browser.

Constructor

new InputHandler(world, enableMouseInteractions)

Parameters:
NameTypeDefaultDescription
worldWorld

world that the handler effects

enableMouseInteractionsBooleantrue

whether particle will interact with mouse (true by default)

Classes

KeyInput

Methods

addKeyEvent(keyInput)

Adds a KeyInput to the list of events that the InputHandler tracks

Parameters:
NameTypeDescription
keyInputKeyInput

startKeyHandling()

Begins key tracking (must be called for key interactions)

startMouseHandling()

Begins mouse tracking (must be called for mouse interactions)