ButtonPosition vs Button

Introduction

ButtonPosition can be used to reference a button based in its physical position rather than by letter. Referencing a button by position can be useful if players are playing your game with gamepads which do not necessarily position their buttons identically.

For example, consider the A, B, X, and Y button positions on the Xbox and Switch controllers.

You may want your game to use the button positions rather than specific button letters when assigning input to your player.

Code Example - Getting Button by ButtonPosition

Entities typically use IPressableInput instances to control actions like jumping. Rather than inspecting the gamepad type, games cna use the ButtonPosition to assign input. For example, the following code might be used to assign the JumpInput:

// The following code assumes JumpInput is a property of type IpressableInput:
this.JumpInput = gamepad.GetButton(ButtonPosition.FaceDown);

Last updated