Skip to main content

FlixelHaptics

View source

interface

org.flixelgdx.backend.FlixelHaptics

public interface 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)

public void vibrate(int ms)

Vibrates the device for the given duration.

Parameters:

NameDescription
msDuration in milliseconds; values less than or equal to zero are ignored.

vibrate(long[], int)

public void vibrate(long[] pattern, int repeat)

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:

NameDescription
patternAlternating off/on durations in milliseconds, starting with the off delay. Must not be null or empty.
repeatIndex into pattern to restart from once the end is reached, or -1 to play the pattern once and stop.

cancel()

public void 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()

public boolean 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.