Skip to main content

FlixelHapticsProvider

View source

interface

org.flixelgdx.input.gamepad.FlixelHapticsProvider

public interface FlixelHapticsProvider

Pluggable vibration backend for FlixelGamepadInputManager.

The built-in implementation, FlixelDefaultHapticsProvider, delegates to gdx-controllers' Controller.startVibration and works on desktop (SDL via gdx-controllers-desktop) and web (W3C Gamepad API via gdx-controllers-teavm) without any extra setup. For platform-specific features such as dual-motor channels, haptic patterns, or DualSense adaptive triggers, supply a custom implementation via FlixelGamepadInputManager.setHapticsProvider(FlixelHapticsProvider).

Intensity values

All intensity parameters are normalized to the range [0, 1], where 0f means no vibration and 1f means full motor strength. Implementations should clamp values outside this range rather than letting them reach the hardware unchecked.

Slot indices

Each method receives the same slot id used throughout FlixelGamepadInputManager. The manager already validates that the slot is in range and that the gamepad system is enabled before calling the provider, so implementations do not need to repeat those checks.

Methods

vibrate(int, float, float, float)

public void vibrate(int slot, float leftIntensity, float rightIntensity, float durationSecs)

Vibrates the controller in the given slot.

The built-in providers for desktop and web honor both motor channels independently. Implementations targeting single-motor hardware may collapse the two intensities to a single value, typically the larger of the two.

Parameters:

NameDescription
slotSlot index between 0 and FlixelGamepadInputManager.MAX_GAMEPADS exclusive.
leftIntensityStrength for the left (low-frequency) motor, in the range [0, 1].
rightIntensityStrength for the right (high-frequency) motor, in the range [0, 1].
durationSecsHow long to vibrate, in seconds.

stopVibration(int)

public void stopVibration(int slot)

Stops any active vibration on the controller in the given slot immediately.

Parameters:

NameDescription
slotSlot index.

canVibrate(int)

public boolean canVibrate(int slot)

Returns whether the controller in the given slot reports haptics support.

Parameters:

NameDescription
slotSlot index.

Returns: true when the slot is connected and the hardware supports vibration.