FlixelHaptics
View sourceinterface
org.flixelgdx.backend.FlixelHaptics
Platform-specific haptic (vibration) feedback for mobile devices.
Access the active implementation via Flixel.haptics. On platforms without a vibration motor (desktop, web), the default no-op implementation is used and all calls are safely ignored. Check FlixelHaptics.isSupported() first if your game logic depends on knowing whether feedback will actually fire.
Launchers on supported platforms (for example, Android) install a real implementation before Flixel.initialize(...) runs. You should not need to assign Flixel.haptics from game code unless you are providing a custom backend.
Example:
// Simple one-shot pulse on a coin pickup.
Flixel.haptics.vibrate(40);
// SOS pattern: three short, three long, three short pulses with no repeat.
Flixel.haptics.vibrate(new long[] { 0, 100, 100, 100, 100, 100, 300, 300, 300, 300, 300, 300, 100, 100, 100 }, -1);
// Stop an ongoing vibration (e.g. the player lets go of a rumble trigger).
Flixel.haptics.cancel();
See Also: Flixel.haptics
Methods
vibrate(int)
Vibrates the device for the given duration.
Parameters:
| Name | Description |
|---|---|
ms | Duration in milliseconds; values less than or equal to zero are ignored. |
vibrate(long[], int)
Vibrates the device following a timed on/off pattern.
Each element in pattern is a duration in milliseconds. The first element is an initial off (silent) delay, the second is the first on period, the third is the next off period, and so on, alternating off and on.
Parameters:
| Name | Description |
|---|---|
pattern | Alternating off/on durations in milliseconds, starting with the off delay. Must not be null or empty. |
repeat | Index into pattern to restart from once the end is reached, or -1 to play the pattern once and stop. |
cancel()
Cancels any active vibration started by FlixelHaptics.vibrate(int) or FlixelHaptics.vibrate(long[], int).
Safe to call even when no vibration is active.
isSupported()
Returns whether haptic feedback is available on this device and platform.
On desktop and web builds this always returns false. On Android it reflects whether the device actually has a vibrator.
Returns: true if calls to FlixelHaptics.vibrate(int) and FlixelHaptics.vibrate(long[], int) will produce real feedback.