An easier way to learn how to use the Haxe core and related technologies.
Tagged with: HaxeFlixel
I recently received a Logitech F310 gamepad. Since HaxeFlixel already has gamepad support (buttons, deadzone, D-Pad, etc.), including support for reading Logitech button input, I figured it would work out-of-the-box, right?
Right?
It turns out that the LogitechButtonID
class contains values based on the Cordless Rumblepad 2 controller. If you look at screenshots, you'll notice the pads all have numbers on them.
That's no good -- the F310 uses A
, B
, X
, and Y
for buttons, with left and right triggers (LB
and RB
respectively). Fortunately, the LogitechButtonID class' comments indicate which value applise to which button; these values match up exactly with the F310. For example:
static inline read only FOUR:Int = 11
Placement equivalent to 'Y' button on the Xbox 360 controller
That only leaves the D-Pads. The built in enum values don't work; instead, I used the four dpad*
properties defined on the controller itself; these work perfectly.
If you want to try this for yourself, it's quite easy:
1) Run flixel create
and then select demo 34
, GamepadTest
.
2) Replace the contents of the GamepadIDs
class with the correct button enum values:
public static inline var A = LogitechButtonID.TWO;
public static inline var B = LogitechButtonID.THREE;
public static inline var X = LogitechButtonID.ONE;
public static inline var Y = LogitechButtonID.FOUR;
public static inline var LB = LogitechButtonID.FIVE;
public static inline var RB = LogitechButtonID.SIX;
public static inline var START = LogitechButtonID.TEN;
public static inline var SELECT = LogitechButtonID.NINE;
public static inline var LEFT_ANALOGUE = LogitechButtonID.LEFT_ANALOGUE;
public static inline var RIGHT_ANALOGUE = LogitechButtonID.RIGHT_ANALOGUE;
public static inline var LEFT_ANALOGUE_X = LogitechButtonID.LEFT_ANALOGUE_X;
public static inline var LEFT_ANALOGUE_Y = LogitechButtonID.LEFT_ANALOGUE_Y;
public static inline var RIGHT_ANALOGUE_X = LogitechButtonID.RIGHT_ANALOGUE_X;
public static inline var RIGHT_ANALOGUE_Y = LogitechButtonID.RIGHT_ANALOGUE_Y;
3) Modify PlayState.hx
's updateDpad
function; the values assigned to the four dpad*
variables should be:
var dpadLeft = _gamePad.dpadLeft;
var dpadRight = _gamePad.dpadRight;
var dpadUp = _gamePad.dpadUp;
var dpadDown = _gamePad.dpadDown;
Run lime test neko
and observe that all input displays as expected.