0.2.1 • Published 3 years ago

eylem v0.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

eylem

npm version MIT licensed

A JavaScript input handling library for animation or game loops

Installation

npm install eylem
// or
yarn add eylem

Usage

Initialize

import Eylem from 'eylem';

const inputs = new Eylem(document, ['horizantal', 'vertical', 'fire']);

Bind keymap

//KeyCode 65:A, 68:D, 83:S, 87:W
inputs.bindInputMap(Eylem.KEY_DOWN, {
  65: { action: 'horizantal', value: -1 },
  68: { action: 'horizantal', value: +1 },
  83: { action: 'vertical', value: -1 },
  87: { action: 'vertical', value: +1 },
});

Bind mouse buttons

// 0 : Left Mouse Button
inputs.bindInputMap(Eylem.MOUSE_DOWN, {
  0: {action : 'fire', value : 1}
});

Watch Mouse Movement

inputs.watchMouse();

Get Inputs

// in a Animation Loop   
function step() {
    const mouseLeft = inputs.getValue('action'); // 0 or 1
    const horizantal = inputs.getValue('horizantal'); // -1 or 0 or 1

    const mouseEvent = inputs.mouse; // MouseEvent Object
    const {offsetX, screenX, movementX} = mouseEvent;

    // clear the inputs at the end
    inputs.clear();
    window.requestAnimationFrame(step);
}

License

Licensed under the MIT license.

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

4 years ago

0.1.1

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago