Code Monkey home page Code Monkey logo

openfl-xinput's Introduction

openfl-xinput

XInput/Xbox 360 controller support for OpenFL on Windows. For the Windows target, given that the user has a 360 controller, here are the key benefits over the OpenFL JoystickEvent:

  • Individual data for each trigger. Under DirectInput you get both triggers as a single bipolar axis (useless)
  • Individual control over each vibrator. Allows for a wide range of haptic feedback.
  • Controller hotswapping. Your game will happily run with or without a controller connected. A controller may get dropped and reconnected to no further detriment to your game.
  • Simplified API. The XBox360Controller class is a one-stop, direct way to get at the game controller.

Usage:

##Initialization Create a new controller with a unique controller ID (zero indexed) You should also check if it's connected.

controller = new XBox360Controller(0);
controller.isConnected();

You can check if the controller is connected without creating an instance

XBox360Controller.isControllerConnected(0);

##Deadzones Set individual stick deadzones with a scalar. You can also set the deadzone precisely with an int within 32767

controller.leftStick.deadZoneNorm = 0.2; 
controller.rightStick.deadZoneNorm = 0.2;

Both triggers share the same deadzone setting, an int from 0 to 255

controller.triggerDeadzone = 30;

##Game update During game updates, call poll() to update the controller state.

controller.poll();

Poll controller for buttons and values. Buttons are booleans, triggers are ints between 0 and 255, sticks are slightly more involved

controller.leftStick.xRaw; //The raw -32767 to 32767 range
controller.leftStick.xNorm; //The range normalized to a bipolar 0-1 scalar, pre-adjusted by the deadzone

##Rumble The 360 controller has two vibrators. In my experience the left vibrator is "coarser" while the right vibrator is "finer".

if (controller.leftBumper.isDown) {
	controller.vibrationLeftNorm = controller.leftTriggerNorm;
}else {
	controller.vibrationLeft = 0; //Vibrations remain set so you have to manually turn them off
}
if (controller.rightBumper.isDown) {
	controller.vibrationRightNorm = controller.rightTriggerNorm;
}else {
	controller.vibrationRight = 0; 
}

The vibrators have quite a nice dynamic range; You can fine control it up to 65535. I've seen games use this to "drive" the vibrators with audio signals. Quite cool.

##Events XBox360Controller buttons are represented with Xbox360Button objects. To receive callbacks when a button is pressed or released, do the following:

function onButtonChange(btn:Xbox360Button):Void 
{
	trace(btn.buttonType, btn.controller.id, btn.isDown);
}

controller.a.onPressed = onButtonChange;
controller.a.onReleased = onButtonChange;

Xbox360Button.buttonType is one of the types found in Xbox360ButtonType.

For convenience, Xbox360Controller has a method for setting listeners on every button.

controller.setButtonListeners(onButtonDown, onButtonUp);
//to clear the listeners, call again with no arguments, or use clearButtonListeners()

openfl-xinput's People

Contributors

sunjammer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openfl-xinput's Issues

Complete source?

This extension is great, but I'm having some trouble to get it to work for Windows XP, I suspect it was built against a too new version of Direct X. I could probably fix that myself, but the source for the extension itself is sadly missing.

Is that something you could be persuaded to post?

More than 4 Controller

If I connect 4 Controller to the PC I can ask for any ID and every ID isConnected = true. But they aren't. If i connect 5th Controller i can not use it.

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.