4.0.3 • Published 2 years ago

nes-cntlr v4.0.3

Weekly downloads
5
License
ISC
Repository
github
Last release
2 years ago

nes-cntlr

Javascript NES controller emulator for keyboards and touch devices

Allow you to use your keyboard and/or a virtual NES Controller (for touch devices) to control whatever you create, like you would with a NES emulator.

alt text

npm i nes-cntlr

Demos

Usage

import NESCntlr from 'nes-cntlr';
let player1 = new NESCntlr();
player1.init();

Events

All events return a 'pressed' parameter bool: true|false. On release, a 'duration' parameter number: ms will also be provided. You can listen to those events for your game/project.

EventParamsDescription
player1:uppressed, durationD-pad
player1:up-rightpressed, durationD-pad
player1:rightpressed, durationD-pad
player1:down-rightpressed, durationD-pad
player1:downpressed, durationD-pad
player1:down-leftpressed, durationD-pad
player1:leftpressed, durationD-pad
player1:up-leftpressed, durationD-pad
player1:selectpressed, durationSelect button
player1:startpressed, durationStart button
player1:bpressed, durationB button
player1:apressed, durationA button

The 'player1' at the beginning of every event match the prefix setting. That way, you can bind multiple nes-cntlr and differentiate which one sent you an event.

Settings

OptionTypeDefaultDescription
colorsarray'#2F3335', '#383d41', '#AC3C66', '#D64A80', '#B4B4B4'Black, Light black, Red, Light red, Grey
keysobject{start: 'Enter', select: 'Space', left: 'ArrowLeft', up: 'ArrowUp', right: 'ArrowRight', down: 'ArrowDown', b: 'KeyZ', a: 'KeyX'}keys mapping.
locationstring'body'Allows you to select where the virtual controller should be injected. ex: .myDiv, #myDiv, etc.
prefixstring'player1'Class prefix
virtualstring'auto''auto', 'never' or 'always' show virtual controller.
zIndexnumber100z-index of the virtual controller.

Browser support

nes-cntlr works on all modern browsers such as Chrome, Firefox, Edge and Safari.

Dependencies

License

Copyright (c) 2018 Simon Arnold

Licensed under the MIT license.

4.0.3

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

6 years ago

3.0.1

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago