Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

key-action-binder

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

key-action-binder

Key-Action-Binder

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Build Status

KeyActionBinder

KeyActionBinder aims to provide universal game input control for both keyboard and game controllers in JavaScript. It works independently of the game engine, the browser, or the hardware platform it is running in.

Goals

  • Having a clear, easy to use interface.
  • Minimizing the amount of support logic needed in a game loop.
  • Providing support for typical game functionality such as button press time tolerance, dead zone protection, and others.
  • Requiring no device or control references to store.
  • Working around browser limitations where appropriate (and possible).
  • Self-containment and independence from any other system, framework, or game engine.
  • Auto-management of gamepad order for sensible party/multi-player support.

Quick usage

Include one of the build files:

<script src="key-action-binder.min.js"></script>

Create a KeyActionBinder instance:

var binder = new KeyActionBinder();

Setup actions with as many bindings as you want:

binder.action("move-left")
	.bind(KeyActionBinder.KeyCodes.LEFT)
	.bind(KeyActionBinder.GamepadButtons.DPAD_LEFT);

binder.action("move-right")
	.bind(KeyActionBinder.KeyCodes.RIGHT)
	.bind(KeyActionBinder.GamepadButtons.DPAD_RIGHT);

binder.action("jump")
	.bind(KeyActionBinder.KeyCodes.SPACE)
	.bind(KeyActionBinder.GamepadButtons.ACTION_DOWN);

Then, evaluate the actions inside your game loop:

function myGameLoop() {
	// Check whether the player should move
	if (binder.action("move-left").activated) {
		// (...code for moving left...)
	} else if (binder.action("move-right").activated) {
		// (...code for moving right...)
	}

	if (playerIsOnGround && binder.action("jump").activated) {
		// (...code for performing jump...)
	}
}

Read more about the project in the wiki.

FAQs

Package last updated on 28 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc