Skip to content

About

A Haxe/Lime extension that implements Haptic Feedback effects on Android and iOS Devices.

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

extension-haptics

A Haxe/Lime extension that implements Haptic Feedback effects on Android and iOS Devices.

Installation

You can install it through Haxelib

haxelib install extension-haptics

Or through Git, if you want the latest updates

haxelib git extension-haptics https://github.com/MultiSliceCrew/extension-haptics.git

Usage

import 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();

Feedback presets

Haptic.impact(LIGHT);
Haptic.impact(HEAVY, 0.7);
Haptic.selection();
Haptic.notification(SUCCESS);
Haptic.notification(ERROR);
  • impact styles are LIGHT, MEDIUM, HEAVY, SOFT and RIGID.
  • 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.

More controls

  • Haptic.cancel() stops the current vibration.

  • Haptic.isSupported() tells if the device can vibrate.

  • Haptic.hasAmplitudeControl() tells if the strength can be changed.

  • Haptic.enabled turns every effect off, and Haptic.intensity scales every effect from 0 to 1.

  • Haptic.minInterval drops effects that come faster than that many seconds, and Haptic.throttled(key, seconds) does the same for one kind of effect.

Patterns

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.

Primitives

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.

Rumble

Haptic.startRumble(amplitude, sharpness, pulse) vibrates until Haptic.stopRumble() or Haptic.cancel(). A pulse above zero beats it on and off.

AHAP files

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.

Licensing

extension-haptics is made available under the MIT License. Check LICENSE for more information.

About

A Haxe/Lime extension that implements Haptic Feedback effects on Android and iOS Devices.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages