@arcade2d/controls
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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);

Readme

Keywords

none

Package Sidebar

Install

npm i @arcade2d/controls

Weekly Downloads

1

Version

0.1.2

License

none

Unpacked Size

13.9 kB

Total Files

18

Last publish

Collaborators

  • martywallace