Hi, I'm still struggling ith the gamepads... I'm trying to get each and every gamepads to do the same thing.
For pressing buttons, I'm using FlxG.gamepads.anyJustPressed(buttonID). But for the joystick movement, I'm clueless...
Here's what I tried to do:
private var gamepad:FlxGamepad;
override public function create():Void
{
super.create();
FlxG.gamepads.globalDeadZone = Util.DEADZONE;
}
override public function update():Void
{
super.update();
gamepad = FlxG.gamepads.lastActive;
if (gamepad != null) {
var newAxis:Int = getAxis(gamepad); switch (newAxis) {
case 1: // DOWN-LEFT, do thing....
case 2: // DOWN, and so on...
}
}
}
// Retrieve Gamepad Axis as an Int corresponding to the numeric pad directions
private function getAxis(gamepad:FlxGamepad):Int
{
var xAxis:Float = gamepad.getXAxis(0);
var yAxis:Float = gamepad.getYAxis(1);
if (xAxis < 0 && yAxis > 0) return 1; // DOWN-LEFT
else if (xAxis == 0 && yAxis > 0) return 2; // DOWN
else if (xAxis > 0 && yAxis > 0) return 3; // DOWN-RIGHT
else if (xAxis < 0 && yAxis == 0) return 4; // LEFT
else if (xAxis > 0 && yAxis == 0) return 6; // RIGHT
else if (xAxis < 0 && yAxis < 0) return 7; // UP-LEFT
else if (xAxis == 0 && yAxis < 0) return 8; // UP
else if (xAxis > 0 && yAxis < 0) return 9; // UP-RIGHT
else return 5; // CENTER
}
Problem is, I only get the last gamepad axis input, even if it is 0, 0.
I think the problem comes from gamepad = FlxG.gamepads.lastActive;
I tried gamepad = FlxG.gamepads.getFirstActiveGamepad(); but the result is worse. It only moves from time to time...
So why isn't there a FlxG.gamepads.anyJustMovedXAxis() ? or something like that? What did I miss?
Thanks for your help :)