A Haxe/Lime extension that implements Haptic Feedback effects on Android and iOS Devices.
You can install it through Haxelib
haxelib install extension-hapticsOr through Git, if you want the latest updates
haxelib git extension-haptics https://github.com/MultiSliceCrew/extension-haptics.gitimport extension.haptics.Haptic;
// Initialize the haptic system
Haptic.initialize();
// Trigger a oneshot vibration
Haptic.vibrateOneShot(0.5, 0.75); // 0.5 seconds duration, 75% intensity
// Trigger a pattern vibration
Haptic.vibratePattern([0.2, 0.4, 0.2], [1.0, 0.5, 0.8]); // Durations and amplitudes
// Dispose of the haptic system
Haptic.dispose();Haptic.impact(LIGHT);
Haptic.impact(HEAVY, 0.7);
Haptic.selection();
Haptic.notification(SUCCESS);
Haptic.notification(ERROR);impactstyles areLIGHT,MEDIUM,HEAVY,SOFTandRIGID.- On iOS these use the system feedback generators.
- On Android they use the predefined click, tick and heavy click effects (Android 10 and newer), with a short vibration on older versions.
-
Haptic.cancel()stops the current vibration. -
Haptic.isSupported()tells if the device can vibrate. -
Haptic.hasAmplitudeControl()tells if the strength can be changed. -
Haptic.enabledturns every effect off, andHaptic.intensityscales every effect from0to1. -
Haptic.minIntervaldrops effects that come faster than that many seconds, andHaptic.throttled(key, seconds)does the same for one kind of effect.
new HapticPattern().tap().pause(0.1).ramp(0.4, 0.2, 1).repeat(2, 0.2).play();
new HapticPattern().beats(128, 8).play();
HapticPattern.heartbeat().play();tap, buzz, pause, ramp, beats, then, repeat, scale and stretch build a pattern. Presets: heartbeat, explosion, countdown, success and failure.
Haptic.primitive(THUD) and Haptic.compose([{primitive: CLICK}, {primitive: QUICK_RISE, delay: 0.05}]) use the Android 12 primitives when the device has them, and a close waveform everywhere else.
Haptic.startRumble(amplitude, sharpness, pulse) vibrates until Haptic.stopRumble() or Haptic.cancel(). A pulse above zero beats it on and off.
Haptic.playAhap(json) plays an Apple AHAP pattern. iOS plays it natively and other platforms convert it with HapticAhap.parse.
On other platforms the effects use lime.ui.Haptic when the Lime in use has it (the lime_haptic define), for example navigator.vibrate on HTML5.
extension-haptics is made available under the MIT License. Check LICENSE for more information.