For starters I’m on a Mac so getting 2+ Xbox 360 controllers to work is already quite a challenge (I documented how to do this here). Apparently PlayStation is a lot easier, and as this site indicates:
“Note that for modern versions of Mac OS X there is a PS3 driver built into the OS and this driver is not required.”
Once I managed to get multiple 360 controllers hooked up properly (link again), I started digging around for how to do this thing.
Reading the docs and Game controllers on Adobe AIR wasn’t clear enough for me (seemed a bit convoluted, or I just say that because it was late at night).
I couldn’t get it to work at first. I thought it was because I didn’t set up the Xbox controller right (Mac insecurities), but after some digging I found that PC users have some of the same issues.
There is also a wonderful code snippet in this post here that can get you started right away in testing… just so you see another number but
Like the devnet article suggests you have to add the listeners
DEVICE_UNUSABLE to your
GameInput instance for it to work properly.
I had a phase where
numDevices was constantly returning
0. Apparently unplugging and re-plugging in the controller can fix this. In my case I restarted the computer and then it worked.
If you’re like me you want some code samples, just to get a general understanding of what needs to be done. Unfortunately these are terribly lacking in Adobe’s documentation, but I found the following to be very helpful.
zehfernando has a wonderful example in plain common english here.
This post (here) I also found very helpful (gives you an idea of what you need to do).
And this post here finally eliminated any further confusion for me.
The last two code samples in the .jp sites are very self-explanatory.
I also quickly put this sample together to give anybody (maybe Google-ing) a general idea of all the info you can capture with this…
GameInputController is not exclusive to AIR anymore, and will “work” (with mixed results) in the browser (from my testing it is perfect in AIR, works in Firefox, but not Crome or Safari).
Also from my reading there are some caveats to running this in the browser, I quote from a helpful answer at stackoverflow:
Not all devices work; some fringe devices may get ignored by Flash.
Sometimes the addition of devices that are supported don’t really work – you may have to disconnect and reconnect them to get them to work.
Sometimes when using multiple controllers of the same type they get mixed up and only one of them will work.
Actual reported control ids vary between the Plugin/ActiveX version of Flash (Firefox/Safari/IE/etc) and Pepper (Chrome).
You usually need to press a button with the proper SWF focused for the GameInputDevice to be detected and reported.
After having found this on github I found zehfernando KeyActionBinder project. It’s a very impressive one, and seems to have solved many of the problems I see I will have.
It will work on Mac/Windows.
There is also Airxbc, but this is Windows only.
I also found James Dean Palmer Gamepad classes.
Although I like zehfernando’s project better from all the others. I recommend that one. His blog posts about his project where a trove of helpful information so I recommend anybody new to this to dive in and start digging at his website.
I got it running in no time, and it was very straightforward.
Ok… now to start making my 2 player+ game…