项目作者: cevherkarakoc

项目描述 :
A JavaScript input handling library for animation or game loops
高级语言: JavaScript
项目地址: git://github.com/cevherkarakoc/eylem.git
创建时间: 2019-06-26T07:33:12Z
项目社区:https://github.com/cevherkarakoc/eylem

开源协议:MIT License

下载


eylem

npm version
MIT licensed

A JavaScript input handling library for animation or game loops

Installation

  1. npm install eylem
  2. // or
  3. yarn add eylem

Usage

Initialize

  1. import Eylem from 'eylem';
  2. const inputs = new Eylem(document, ['horizantal', 'vertical', 'fire']);

Bind keymap

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

Bind mouse buttons

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

Watch Mouse Movement

  1. inputs.watchMouse();

Get Inputs

  1. // in a Animation Loop
  2. function step() {
  3. const mouseLeft = inputs.getValue('action'); // 0 or 1
  4. const horizantal = inputs.getValue('horizantal'); // -1 or 0 or 1
  5. const mouseEvent = inputs.mouse; // MouseEvent Object
  6. const {offsetX, screenX, movementX} = mouseEvent;
  7. // clear the inputs at the end
  8. inputs.clear();
  9. window.requestAnimationFrame(step);
  10. }

License

Licensed under the MIT license.