Skip to main content

Basic Use

This chapter covers the basic use of the Interhaptics extension.

Initialisation

The first thing to do is initialising the extension using interhaptics_init.

After that, you should check for the presence of a "provider", which is an attached device (e.g. a controller) that is capable of providing haptics feedback. To initialise the provider, call interhaptics_providers_init. To check if a provider is present, call interhaptics_providers_available.

/// Create Event
interhaptics_init();
interhaptics_providers_init();

Loading .haps Files

Haptics effects are stored in .haps files, which use a custom file format used by Interhaptics.

You can add a haptics effect stored in a .haps file using interhaptics_add_hm:

var _file = file_text_open_read("HapticMaterials/BodyHit.haps")
var _content = file_text_read_string(_file);
file_text_close(_file);

hm_index = interhaptics_add_hm(_content);

You can then add one or more targets for this haptics effect:

var _commanddata =
{
sign: INTERHAPTICS_OPERATOR.PLUS,
group: INTERHAPTICS_GROUP_ID.PALM,
side: INTERHAPTICS_LATERAL_FLAG.GLOBAL
};

interhaptics_add_target_to_event(hm_index, [_commanddata]);

Updating Interhaptics

To update Interhaptics, you should first compute all haptics events, then render the haptics every step:

/// Step Event
var _time = current_time / 1000;
interhaptics_compute_all_events(_time);
interhaptics_providers_render_haptics();

Playing A Haptic Effect

Use interhaptics_play_event to play a haptic effect:

interhaptics_play_event(hm_index, -time, 0, 0);

Cleaning Up

/// Clean Up Event
interhaptics_providers_clean();
interhaptics_quit();