Skip to content
Thomas Cashman edited this page Nov 16, 2016 · 4 revisions

Keyboard / Mouse / Touchscreen

See LibGDX Input Handling documentation.

Game Controllers

Requires mini2Dx 1.3.0 or above

mini2Dx builds on top of LibGDX's Controller API to add explicit mappings and interfaces for common game controllers. The currently supported controllers are:

  • Xbox 360 Controller
  • Xbox One Controller

Playstation controllers are currently planned also.

Controller Mapping

To get access to a specific controller mapping, first retrieve the Controller instance through the LibGDX API and then switch over the mapping using the ControllerMapping class.

//Retrieve controller using LibGDX API
Controller controller = ...;

switch(ControllerMapping.getControllerType(controller)) {
case ControllerType.XBOX_ONE:
	return ControllerMapping.xboxOne(controller);
case ControllerType.XBOX_360:
	return ControllerMapping.xbox360(controller);
...
}

The framework will return an implementation of MdxController corresponding to controller, for example Xbox360Controller

Once you have your controller instance you can attach listeners to it. The API also provides adapter classes for you to extend in case you don't want to implement the listener interfaces.

Handling dead zones

Dead zones are a common problem for analog sticks. Mini2Dx provides dead zone handling built into the API. Based on Doing Thumbstick Dead Zones Right there are several dead zone handling implementations available.

  • AxialDeadZone
  • RadialDeadZone
  • ScaledRadialDeadZone

To apply them to your controllers, pass the instances as an argument when creating the controller.

RadialDeadZone leftStickDeadZone = new RadialDeadZone();
RadialDeadZone rightStickDeadZone = new RadialDeadZone();

//Retrieve controller using LibGDX API
Controller controller = ...;

switch(ControllerMapping.getControllerType(controller)) {
case ControllerType.XBOX_ONE:
	return ControllerMapping.xboxOne(controller, leftStickDeadZone, rightStickDeadZone);
case ControllerType.XBOX_360:
	return ControllerMapping.xbox360(controller, leftStickDeadZone, rightStickDeadZone);
...
}

Clone this wiki locally