Skip to content

A JavaScript input handling library for animation or game loops

License

Notifications You must be signed in to change notification settings

cevherkarakoc/eylem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A JavaScript input handling library for animation or game loops

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published