KeyActionBinder is growing up

After a lot of breaking things, refactoring, and testing, I’ve finally merged the experimental branch of KeyActionBinder into the main branch of the project. The biggest change, of course, is making the functionality of this gamepad support library more automatic, in the sense that it tries to detect whatever game device the user has connected and map its inputs accordingly, so game developers don’t have to care about writing hundreds of lines of code to have their games work when doing cross-platform (or even single-platform) development in AS3 and Adobe AIR.

On top of that, I’ve also started doing a lot more of mapping work (using the test interface I mentioned earlier) and adding them to KeyActionBinder’s new separate list, which is now just a long JSON meant to be easily edited. This is what the library supports right now:

  • Windows 7
    • XBox 360 controller
    • PlayStation 4 DS4
    • NeoFlex (generic Gamepad)
  • OUYA
    • Native controller
    • XBox 360 controller
    • Playstation 3 DS3
    • Playstation 4 DS4
  • OSX
    • Playstation 3 DS3 (standard plugin version)
    • Playstation 3 DS3 (standard plugin version)

However, several other developers started contributing to the project, and I have a long list of mapping that I will be adding soon (I have to adapt them to a new format I’m using in the JSON file).

Syntax-wise, it hasn’t changed much. Usage is like so:

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

// Create an instance somewhere
binder = new KeyActionBinder();

// During startup, add as many bindings as you want, using your own action ids
binder.addKeyboardActionBinding("move-left", Keyboard.LEFT);
binder.addKeyboardActionBinding("move-right", Keyboard.RIGHT);
binder.addGamepadActionBinding("jump", Keyboard.SPACE);
binder.addGamepadActionBinding("move-left", GamepadControls.DPAD_LEFT);
binder.addGamepadActionBinding("move-right", GamepadControls.DPAD_RIGHT);
binder.addGamepadActionBinding("jump", GamepadControls.ACTION_DOWN);

// Finally, during the game loop, check the values
if (binder.isActionActivated("move-left")) {
    playerSpeedX = -1;
} else if (binder.isActionActivated("move-right")) {
    playerSpeedX = 1;
}
if (isPlayerOnTheGround && binder.isActionActivated("jump", 0.03)) {
    // Will only jump if activated in the last 0.03s
    // This prevents a player being able to press jump while in mid-air
    playerSpeedY = -1;
    // Consume action so it won't be true in next frame
    // This prevents a player from jumping continuously
    binder.consumeAction("jump");
}

There are other use cases, but that’s the basics. See the rest in the project page.

I started this project just as a support system for a game I’m developing in my free time, but considering the complexity of supporting several different devices and their own custom control inputs, it soon became obvious this had to be a more public effort – one that more people could help, and benefit from. I’m pretty excited it’s finally taking form! It still has a long way to go, but it’s quickly becoming a pretty solid solution, in my opinion.

2 responses

  1. Thanks Zeh, having issues with controls on OSX, and I just came here to ask if you’d ever tested it there. Lo and behold, you’re miles ahead of me, THANKS!

    • Thanks Shawn. Yes, it’s supposed to work well with OSX; but truth be told, I haven’t tested it very recently (I’m mainly a windows guy). If you notice anything weird let me know, binding fixes and additions should be quick and easy.

Comments are closed.