0

I'm posting this question because i'm having a little problem with the GameInput API in an adobe AIR desktop app. I tested the API in a test app and it worked just fine. However, when i added it to my real app (a game), it doesn't trigger anymore at startup.

Everything else works, and if i disconnect/reconnect the controller, everything works fine. However, the initial trigger of the callback function isn't working anymore.

Any idea why ? Here's what i do:

        if (GameInput.isSupported) //GAMEPADS SUPPORT
        {
            gameInput = new GameInput();
            gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, controllerAdded);
            gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, controllerRemoved);
            gameInput.addEventListener(GameInputEvent.DEVICE_UNUSABLE, controllerProblem);
        }                           //GAMEPAD SUPPORT

    public function controllerAdded(e:GameInputEvent):void
    {
        var vec:Vector.<String> = new Vector.<String>();

        gamepad = GameInput.getDeviceAt(0);
        vec[0] = gamepad.getControlAt(0).id;
        gamepad.enabled = true;
        gamepad.sampleInterval = 10;
        gamepad.startCachingSamples(5, vec); // numSamples = 5
        for (var i:int = 0; i < gamepad.numControls; ++i)
            gamepad.getControlAt(i).addEventListener(Event.CHANGE, handleChangeEvent);
    }

I am guessing it could be a focus issue or something related but i really don't see why this would be happening. My app looks like this: Core (class called from swf and manages the whole app)

Screens (different classes that inherit movieclip but have logic inside, such as game, optionscreen, etc.)

The Gameinput api intialization is done in the core, after the instanciation of the object (using Event.ADDED_TO_STAGE).

2 Answers2

0

The GameInputEvent class represents an event that is dispatched when a game input device has either been added or removed from the application platform

So if you launch the app and allready have a device, no event will be triggered which sounds like your issue. Why don't you just check devices during intialization and then work with them at that point?

if (GameInput.isSupported) //GAMEPADS SUPPORT
{
    gameInput = new GameInput();
    gameInput.addEventListener(GameInputEvent.DEVICE_ADDED, controllerAdded);
    gameInput.addEventListener(GameInputEvent.DEVICE_REMOVED, controllerRemoved);
    gameInput.addEventListener(GameInputEvent.DEVICE_UNUSABLE, controllerProblem);
    if(GameInput.numDevices > 0) { 
        /*enter code here/* 
    }
}    
Daniel MesSer
  • 1,191
  • 1
  • 7
  • 13
  • No, it doesn't work like this. If a device was connected before startup and is not immediately available, a DEVICE_ADDED event will be dispatched when the device becomes available for use. As i said, i had no issue with another app i tested this with. My problem comes from something else than the API itself but i'm not seeing what it is.I obviously can't post the whole code for the app here as i have 100+ files and some are 1000 lines long xD What i did though, was test the numDevices and it's 0 on both apps. On the "working" one, it then sends events for the controllers already plugged in. – Fabrice Bacquart Jul 17 '15 at 00:25
0

Well it seems the GameInput API by Adobe is too unstable.

I've decided to use AirControl instead and it works much better... I'm therefore closing this question.