I'm using the GameInput class on OUYA to use the controllers. When calling GameInput.numDevices, I get 1 (for the controller I have connected), but when asking GameInput.getDeviceAt(0), I get a null.
I've tried with AIR 3.7 and 3.8 beta. Is there anything I can do to fix this?
Thank you in advance!
Yep, even a 1ms delay will prevent the DEVICE_ADDED from being fired. Basically, a Frame 1 thing I guess...
It's good that there's a workaround, but clearly a bug within the GameInput API, if numDevices = 1, getDeviceAt(0) should obviously not be getting GC'd.
Wow, I'm seeing HUGE performance issues coming from GameInput.
The red spikes are a TIMER event, seemingly coming from GameInput. The Red line is my Frame Budget of 16ms... you guys are using 65ms inside your Timer handler... if anyone is counting, that's 4 entire frames dropped.
This manifests in-game as a horrible jerkiness, every 1 second, my game skips a beat and all characters jump into different positions.
It seems to only happen on Desktop, which is a bit of a saving grace I suppose.
Ohhh that's great to know. Thanks for the research guys! There's a few ways I think I can work around this on my code, will have to try it out. Trying to avoid explicity calling it in my document class, will try in the static initializer of a class.
About the timer/delays: yes it's a ridiculous waste of CPU. And yes it's only in the desktop version (thankfully). Adobe is aware of the problem but nothing has been done so far I think.
Thanks zeh, I found your class this morning and it's brilliant! After instanciating it in my document class, everything works great.
@shawnb81: you killed it, that was exactly the problem. If the GameInput listening instance is not initialized in frame 1 (maybe it's a timing thing), it never works. It doesn't dispatch events, and the device list is never valid.
If you're interested, I've updated my KeyActionBinder class to help somewhat with that. The problem is still there, but at least now the GameInput listener instance is created on a static initializer. That means that you don't have to necessarily create a KeyActionBinder instance, but merely refer to it. On my game prototype, I simply have this in my SWF document class:
// Refer to input binding class to force initialization KeyActionBinder;
And now it works. It's hacky but... it's something until it's fixed.
Nice, I decided to add a static initialization function to your class, that I just call in my Constructor.
Btw, where did yhour Donate button go?? I wanted to show my appreciation with some free beers
I recently tried using GameInput in a single frame .FLA (with no Document Class), compiled with Flash CS6 and Adobe AIR 22.214.171.1240 set as target, and tested by side loading with adb to NVIDIA Shield, and the GameInputEvent.DEVICE_ADDED event was not being fired when the GameInput instance and GameInputEvent listeners were placed in a function such as start() that was being triggered later by user interaction.
I too have confirmed during my own testing that GameInput must be instantiated (along with GameInputEvent listeners added to it) on the first frame, or the event does not fire...
By moving the code immediately after the imports, it started working as expected:
gameInput = new GameInput();
If you are using a Document Class, make sure it's in the Document Class constructor.
If you aren't using a Document Class, make sure it's on frame 1 immediately after your imports.
And Zeh, nice job with your GameInput testing interface and KeyActionBinder library — super awesome work!