Gamepad Support
Introduction
Gum Forms supports using a gamepad to control the UI. In general, when using a gamepad a single UI control has focus. Pressing up or down on the gamepad moves focus to the next item. Each forms control can support different interaction. For example, Buttons can be clicked, but a ListBox supports selecting items within the ListBox.
Enabling Gamepad Controls
To enable gamepad support in your screen:
Be sure to have a gamepad plugged in. Any gamepad that is usable in MonoGame will also work as a gamepad in Gum Forms
Add the gamepad to the FrameworkElement.GamepadsForUiControl. You can add multiple gamepads for multiplayer games.
Set the initial control to have focus by setting its
IsFocused = true
For example, the following code enables gamepad control for a game assuming MyButton is a valid button:
Button Control Click
By default a gamepad's A button can be used to select the focused control. If the focused control is a Button
then pressing a gamepad's A button. The following example code shows how to detect clicks on a button which happen with the gamepad:
Pressing the A button raises the focused button's Click event.
Handling buttons specifically can be handled by subscribing to ControllerButtonPushed.
The Click event may be raised with InputEventArgs containing the gamepad. Remember, clicks can happen a variety of ways including the mouse or even being directly invoked, so you need to check whether the second parameter is of type InputEventArgs
and if the device is a GamePad.
If additional flexibility is needed, gamepad events can be polled in an Update method.
Last updated
Was this helpful?