Coder Social home page Coder Social 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/JoystickEvent 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();

##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.state.triggerDeadzone = 30;

##Game update During game updates, call poll() to update the controller state. The returned state is natively updated at 20hz so frequency here is not a must.

controller.poll();

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

controller.state.leftStick.xRaw; //The raw -32767 to 32767 range
controller.state.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.state.leftBumper) {
	controller.vibrationLeftNorm = controller.state.leftTriggerNorm;
}else {
	controller.vibrationLeft = 0; //Vibrations remain set so you have to manually turn them off
}
if (controller.state.rightBumper) {
	controller.vibrationRightNorm = controller.state.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.

openfl-xinput's People

Contributors

sunjammer avatar

Watchers

 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.