Code Monkey home page Code Monkey logo

key-action-binder-as3's Introduction

KeyActionBinder

KeyActionBinder tries to provide universal game input control for both keyboard and game controllers in Adobe AIR, independent of the game engine used or the hardware platform it is running in.

While Adobe Flash already provides all the means for using keyboard and game input (via KeyboardEvent and GameInput), KeyActionBinder tries to abstract those classes behind a straightforward, higher-level interface. It is meant to be simple but powerful, while solving some of the most common pitfalls involved with player input in AS3 games.

Using KeyActionBinderReferenceVersion ChangelogSupported devicesContribute

Goals

  • Unified interface for keyboard and game controller input
  • Made to be fast: memory allocation is kept to a minimum, and there are no device references or instances to maintain
  • Abstract actual controls in favor of action ids: easier to configure key bindings through variables, with redundant input types (keyboard and gamepad)
  • Automatic bindings on any platform by hiding away platform-specific controls over unified ids
  • Self-containment and independence from any other system or framework

Usage

private var binder:KeyActionBinder;

// Setup (first frame/root of SWF)
KeyActionBinder.init(stage);

public function setup():void {
	// Create instance
	binder = new KeyActionBinder();
	
	// Setup as many action bindings as you want
	binder.addKeyboardActionBinding("move-left", Keyboard.LEFT);
	binder.addKeyboardActionBinding("move-right", Keyboard.RIGHT);
	binder.addGamepadActionBinding("move-left", GamepadControls.DPAD_LEFT);
	binder.addGamepadActionBinding("move-right", GamepadControls.DPAD_RIGHT);
}

function function gameLoop():void {
	// Evaluate actions
	if (binder.isActionActivated("move-left")) {
		// ...
	} else if (binder.isActionActivated("move-right")) {
		// ...
	}
}

Read more in the guide.

Tests/demos

KeyActionBinderTester
KeyActionBinderTester
Web-based version, Android/OUYA APK
Source code

Read more

GameInput problems

In case of problems with KeyActionBinder... know that Flash's GameInput API is still severely ridden with bugs. You may run into some of them. Here's some more information.

I'll remove items from the list when they're fixed.

Credits and thanks

  • James Dean Palmer for the original idea about auto-mapping controls and many bindings
  • Patrick Bastiani for the NeoFlex controller mapping
  • Rusty Moyher for the Buffalo SNES mapping, and several other mappings for Windows and OSX
  • Eric Socolofsky for testing, bug fixes, and OSX mappings for the XBox 360 controller
  • mwgray for important bug fixes and features

License

KeyActionBinder uses the MIT License. You can use this code in any project, whether of commercial nature or not. If you redistribute the code, the license (LICENSE.txt) must be present with it.

To-do

  • Use caching samples? Change sampling rate?
  • Properly detect buttons that immediately send down+up events that cannot be detected by normal frames (e.g. HOME on OUYA)
  • Allow detecting "any" gamepad key (for "press any key")
  • More automatic gamepad mappings
  • Still allow platform-specific control ids?
  • Profile and test performance/bottlenecks/memory allocations
  • A better looking KeyActionBinderTester demo
  • Compile binary/stable SWC
  • More bulletproof support for 2+ controllers

key-action-binder-as3's People

Contributors

zeh avatar ericsoco avatar mwgray avatar girasquid avatar

Watchers

James Cloos avatar Ben Follington avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.