IOS7: Add dpad actions to gamepad controller

Some game engines requires the dpad to control a character. The GRIM
engine is an example of this where the user steer the character by
the arrow keys or dpad controller.
This commit is contained in:
Lars Sundström 2023-02-07 23:02:23 +01:00 committed by Eugene Sandulenko
parent fac7008914
commit 045ddca927

View File

@ -91,6 +91,14 @@
[self handleJoystickAxisMotionX:x andY:0-y forJoystick:kGameControllerJoystickRight];
};
_controller.extendedGamepad.dpad.valueChangedHandler = ^(GCControllerDirectionPad * _Nonnull dpad, float xValue, float yValue) {
// Negative values are left/down, positive are right/up, 0 is no press
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_LEFT isPressed:(xValue < 0)];
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_RIGHT isPressed:(xValue > 0)];
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_UP isPressed:(yValue > 0)];
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_DPAD_DOWN isPressed:(yValue < 0)];
};
_controller.extendedGamepad.buttonA.valueChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) {
[self handleJoystickButtonAction:Common::JOYSTICK_BUTTON_A isPressed:pressed];
};