sparkar-event-helpers

1.0.1 • Public • Published

Spark AR - Event Helpers

Description

This is a helper package that includes a utility for scheduling repeated, randomized events, and a utility for limiting the repeated execution of a provided event function.

Usage

const Audio = require("Audio");
const Time = require("Time");
const TouchGestures = require("TouchGestures");

const EventHelpers = require("sparkar-event-helpers");

// Sonar sound playback controller & event function
const sonarController = Audio.getPlaybackController("sonar_controller");
function playSonarSound() {
  sonarController.reset();
  sonarController.setPlaying(true);
}

// Tap sound playback controller & event function
const tapController = Audio.getPlaybackController("tap_controller");
function playTapSound() {
  tapController.reset();
  tapController.setPlaying(true);
}

// Play the sonar sound every 2-4 seconds, and cancel after 10 seconds
const sonarEvent = EventHelpers.scheduleEvent({
  eventFunction: playSonarSound,
  minTime: 2000,
  maxTime: 4000,
});
Time.setTimeout(() => {
  sonarEvent.cancel();
}, 10000);

// Play the tap sound when tapping the screen, at most once each second
const limitedTapEvent = EventHelpers.makeLimitedEvent({
  eventFunction: playTapSound,
  maxFrequency: 1000,
});
TouchGestures.onTap().subscribe(limitedTapEvent);

Readme

Keywords

Package Sidebar

Install

npm i sparkar-event-helpers

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

5.62 kB

Total Files

3

Last publish

Collaborators

  • man1