Skip to main content
Participant
June 12, 2013
Beantwortet

Is GameInput supported in Windows?

  • June 12, 2013
  • 2 Antworten
  • 3081 Ansichten

I have several Xbox 360 controllers that I would like to connect to my AS3 game. Is this even possible or should I stop trying?

Currently the only code I have in my AIR 3.7 project is "GameInput.isSupported" and it returns false.

Dieses Thema wurde für Antworten geschlossen.
Beste Antwort von wdhoward

Support for GameInput is currently only supported on Android.  However, in the next major release of Flash Player and the AIR SDK, GameInput support will be added to FlashPlayer and desktop AIR.  You can get the current beta of both Flash Player and the AIR SDK and try it out!  The release notes for the beta release don't show it, but it's there.  We will get those updated!  Have fun!

2 Antworten

MJD1981
Inspiring
June 16, 2013

I had a pleasant surprise this morning when I experimented with it in AIR 3.8 beta and everything worked perfectly with an Xbox controller in Windows! Had every single button mapped and working effortlessly within a few minutes.

Participant
June 16, 2013

Could you post the code or project? I'm currenty trying to do the same and with Air 3.8 it says controllers are supported, but doesn't find any when I connect Xbox controllers (even when plugged in advance, though they work in other games)

Known Participant
November 23, 2015

And annoyingly, as is always the way, I solved it shortly after posting the above.


When you create your gameInput object, one needs to ensure that the variable doesn't fall out of scope... as in, make sure you create a "private var gameInput:GameInput" as a Class property, then instantiate and add the event listeners.


I've done:

"var something:SomeClass;"

Attached event listeners and whatnot and done this many times before - only for testing! - and been OK.  But this time I got bitten by the variable falling out of scope, as one would expect!

My simple class contains:

package

{

          import flash.display.Sprite;

          import flash.events.GameInputEvent;

          import flash.text.TextField;

          import flash.ui.GameInput;

          public class GameInputTest extends Sprite

          {

                    private var gameInput:GameInput;

                    private var textField:TextField;

                    public function GameInputTest()

                    {

                              super();

                              this.init();

                    }

                    private function init():void

                    {

                              this.textField = new TextField();

                              this.textField.x = 10;

                              this.textField.y = 10;

                              this.textField.width = this.textField.height = 400;

                              this.textField.multiline = true;

                              this.textField.text = "Game Input Controller Test";

                              this.addChild( this.textField );

                              gameInput = new GameInput();

                              gameInput.addEventListener( GameInputEvent.DEVICE_ADDED, controllerAdded );

                              gameInput.addEventListener( GameInputEvent.DEVICE_REMOVED, controllerRemoved );

                              gameInput.addEventListener( GameInputEvent.DEVICE_UNUSABLE, controllerUnusable );

                              //trace( "GameInput.isSupported: " + GameInput.isSupported );

                              //trace( "GameInput.numDevices: " + GameInput.numDevices );

                              //trace( "GameInput.getDeviceAt: " + GameInput.getDeviceAt( 0 ) );

                    }

                    private function controllerAdded( gameInputEvent:GameInputEvent ):void

                    {

                              this.textField.appendText( "Controller Added." );

                              this.textField.appendText( "GameInput.numDevices: " + GameInput.numDevices );

                              trace( "Controller Added." );

                              trace( "GameInput.numDevices: " + GameInput.numDevices );

                    }

                    private function controllerRemoved( gameInputEvent:GameInputEvent ):void

                    {

                              this.textField.appendText( "Controller Removed." );

                              trace( "Controller Removed." );

                    }

                    private function controllerUnusable( gameInputEvent:GameInputEvent ):void

                    {

                              this.textField.appendText( "Controller Unusable." );

                              trace( "Controller Unusable." );

                    }

          }

}

That works fine, the TextField gets updated as do the trace() methods get called.

Hope this helps someone :-)

Tested and working on both Windows and OUYA :-)


oh god, thanks, that worked for me \o/

wdhowardAntwort
Participant
June 12, 2013

Support for GameInput is currently only supported on Android.  However, in the next major release of Flash Player and the AIR SDK, GameInput support will be added to FlashPlayer and desktop AIR.  You can get the current beta of both Flash Player and the AIR SDK and try it out!  The release notes for the beta release don't show it, but it's there.  We will get those updated!  Have fun!