Questions about gamepad, one at a time...

  • Hi, I've updated a game I made one year ago for the Ouya. Since then, I've updated Flixel and other libs to their lastest versions. Now gamepads don't work anymore...
    So I have several problems for you guys. Let's start with the first one:

    Dpad is working weird on OUYA

    Here's the function I wrote for retreiving the directional pad or analog stick for any gamepads:

    public static inline function getAxis():Int
    	var gamepads:Array < FlxGamepad > = FlxG.gamepads.getActiveGamepads();
    	var d:Int = 0;
    	for (gamepad in gamepads)
    		var xAxis:Float = gamepad.analog.value.LEFT_STICK_X;
    		var yAxis:Float = gamepad.analog.value.LEFT_STICK_Y;
    		if (gamepad.justPressed.DPAD_LEFT)	xAxis = -1;
    		if (gamepad.justPressed.DPAD_RIGHT)	xAxis = 1;
    		if (gamepad.justPressed.DPAD_UP)	yAxis = -1;
    		if (gamepad.justPressed.DPAD_DOWN)	yAxis = 1;
    		if	(xAxis < 0	&& yAxis > 0)	d = 1;	// DOWN-LEFT
    		else if	(xAxis == 0	&& yAxis > 0)	d = 2;	// DOWN
    		else if	(xAxis > 0	&& yAxis > 0)	d = 3;	// DOWN-RIGHT
    		else if	(xAxis < 0	&& yAxis == 0)	d = 4;	// LEFT
    		else if	(xAxis > 0	&& yAxis == 0)	d = 6;	// RIGHT
    		else if	(xAxis < 0	&& yAxis < 0)	d = 7;	// UP-LEFT
    		else if	(xAxis == 0	&& yAxis < 0)	d = 8;	// UP
    		else if	(xAxis > 0	&& yAxis < 0)	d = 9;	// UP-RIGHT
    	return d;

    At first, I was using

    if (FlxG.gamepads.anyJustPressed(FlxGamepadInputID.DPAD_LEFT))	xAxis = -1;

    for each axes, but I didn't find how tu use something similar for the analog stick.
    Nevermind, it works great on Flash build. But when I try the apk on the OUYA I obtain three different behaviors with the Dpad:

    1. After the game has launched, the action seems to be called twice. For example, in the entry menu, when I press Dpad up, the menu goes up two times instead of once. It's the same for all directions.
    2. After I move the analog stick, the Dpad act differently: the action is called for press and for release. Don't know why...
    3. After I switch the FlxState, the Dpad is working fine.

    Do you know what can I do to repair that?
    ( Then we'll talk about the buttons ... )

  • Nailed it!

    It didn't came from my code but from Android behavior regarding keyboard (at least on OUYA and on my GSM with the NES30 gamepad. I've tried on NVIDIA Shield TV but Dpad isn't recognized).
    Is it normal that if (FlxG.keys.justPressed.UP) returns true when you press OR release Dpad up on Android? I believe it's something that was not there last year... If so I'll update my code so it is not called twice for the keyboard and the gamepad :)

  • There comes my second problem with the gamepad:

    Why the buttons positions are inconsistent between systems?

    Same as before, I've wrote a simple button handler for all active gamepads:

    public static inline function getButton(button:String):Bool
    	var gamepads:Array< FlxGamepad > = FlxG.gamepads.getActiveGamepads();
    	var press:Bool = false;
    	for (gamepad in gamepads)
    		switch (button)
    			case "OK":	press = gamepad.justPressed.A;
    			case "BACK":	press = gamepad.justPressed.B;
    			case "QUIT":	press = gamepad.justPressed.Y;
    	return press;

    Assuming that the Gamepad doc is right , checking gamepad.justPressed.Y; should return the state of the Y button on the gamepad.
    So I've tried with an XBOX controller and a PS3 one, everything is fine for the Flash export.
    But when I play my game on OUYA, the Y button is swapped with the X button (I'm talking about XBOX layout. To make it simple, I'll always put the XBOX layout in bold otherwise explanations are going to be complicated). So these two buttons are swapped on the OUYA gamepade (U/Y), but also on the PS3 gamepad (square/triangle).

    I've checked the mapping on OUYA, and it should work:

    case OUYAID.O: A;
    case OUYAID.A: B;
    case OUYAID.U: X;
    case OUYAID.Y: Y;

    Am I missing something?

    Also you may wonder why the heck I'm still struggling with my "almost dead" OUYA? It's because the NVIDIA shield TV gamepad is not supported yet (and that's gonna be my next question).

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.