Google Groups

Re: FlxG.gamepads.anyJustMovedXAxis ?


Ats Feb 12, 2015 4:18 AM
Posted in group: HaxeFlixel
OK, so I've obtained what I wanted by adding two functions in FlxGamepadManager.hx :

 public function anyMoveXAxis(AxisID:Int):Float
 
{
   
for (gamepad in _gamepads)
   
{
          var axisValue:Float = gamepad.getXAxis(AxisID);

     if ((gamepad != null) && axisValue != 0)
     {
       
return axisValue;
     
}
   
}
 
 
return 0;
 
}
 
 
public function anyMoveYAxis(AxisID:Int):Float
 
{
   for (gamepad in _gamepads)
   
{
          var axisValue:Float = gamepad.getYAxis(AxisID);

     if ((gamepad != null) && axisValue != 0)
     {
       return axisValue;
     
}
   
}
 
 
return 0;
 
}


And by calling them using

public static inline function getAxis():Int
{
 
var xAxis:Float = FlxG.gamepads.anyMoveXAxis(LEFT_ANALOGUE_X);
 
var yAxis:Float = FlxG.gamepads.anyMoveYAxis(LEFT_ANALOGUE_Y);


 
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
}

Do you think it is possible to add those two functions into haxeflixel sourcecode? Or is there a simple way to do the same without that?
Thanks


On Thursday, February 12, 2015 at 10:08:40 AM UTC+1, Ats wrote:
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 :)