@arcade2d/controls
v0.1.2
Published
Game control input library.
Downloads
14
Readme
Controls
Input detection components for browser-based game controls.
Installation
$ yarn add @arcade2d/controls
Examples
Keyboard Input
import {
KeyboardInput,
KeyboardInputEvent,
KeyboardState,
} from '@arcade2d/controls';
// Define keyboard input manager instance.
const keyboard = new KeyboardInput(document);
// Handle key press and release handlers.
keyboard.onKeyPress((event: KeyboardInputEvent) =>
console.log('press', event.key),
);
keyboard.onKeyRelease((event: KeyboardInputEvent) =>
console.log('release', event.key),
);
// Check keyboard state during a loop.
setInterval(() => {
const state: KeyboardState = keyboard.getState();
if (state.isDown('a')) {
console.log('a is held down');
}
}, 16);