KeyActionBinder provides universal game input control for both keyboard and game controllers in Adobe AIR. It is 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 games.
In KeyActionBinder, it’s possible to evaluate your own arbitrary “actions” instead of specific keys or controls. On the game loop those actions can be check and processed. For actions that are not repeated, like a player jump, it’s possible to “consume” them via consumeAction()
. This forces the player to activate the button again if they want to perform the action again.
Sample
binder = new KeyActionBinder(stage); // keyboard binding binder.addKeyboardActionBinding("move-left", Keyboard.LEFT); binder.addKeyboardActionBinding("move-right", Keyboard.RIGHT); / gamepad binding binder.addGamepadActionBinding("move-left", GamepadControls.WINDOWS_DPAD_LEFT); binder.addGamepadActionBinding("move-right", GamepadControls.WINDOWS_DPAD_RIGHT); // evaluating actions if (binder.isActionActivated("move-left")) { // Move the player to the left... // Optional: consume action consumeAction("move-left"); } else if (binder.isActionActivated("move-right")) { // Move the player to the right... } // gamepad bindings (analog) binder.addGamepadSensitiveActionBinding("run-speed", GamepadControls.WINDOWS_L2_SENSITIVE); // L2/LT binder.addGamepadSensitiveActionBinding("axis-x", GamepadControls.WINDOWS_STICK_LEFT_X, NaN, -1, 1); // Any player, min value, max value binder.addGamepadSensitiveActionBinding("axis-y", GamepadControls.WINDOWS_STICK_LEFT_Y, NaN, -1, 1); // ... in the game loop var runSpeed:Number = binder.getActionValue("run-speed"); // Value will be between 0 and var speedX:Number = binder.getActionValue("axis-x"); // Value will be between -1 and 1 var speedY:Number = binder.getActionValue("axis-y");
Andrey Kyznetsov liked this on Facebook.