// // orbSound.js // // created by Rebecca Stankus on 02/14/18 // Copyright 2018 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // (function() { var _this; var AUDIO_VOLUME_LEVEL = 1; var TIMEOUT_100_MS = 100; var UPDATE_POSITION_MS = 50; var TIMEOUT_10000_MS = 10000; var playing = false; var sound; var interval; var injector; var OrbRed = function() { _this = this; }; OrbRed.prototype = { preload: function(entityID){ _this.entityID = entityID; sound = SoundCache.getSound(Script.resolvePath("sounds/14369__acclivity__chimebar-g-low.wav")); }, collisionWithEntity: function(thisEntity, otherEntity, collision) { if (collision.type === 0) { this.playSound(); } }, playSound: function() { if (interval) { Script.clearInterval(interval); } _this.homePos = Entities.getEntityProperties(_this.entityID, ["position"]).position; _this.injector = Audio.playSound(_this.sound, {position: _this.homePos, volume: AUDIO_VOLUME_LEVEL}); if (sound.downloaded && !playing) { Audio.playSound(sound, { position: _this.homePos, volume: AUDIO_VOLUME_LEVEL }); playing = true; Script.setTimeout(function() { interval = Script.setInterval(function() { var newAudioPosition = Entities.getEntityProperties(_this.entityID, 'position').position; injector.options = { position: newAudioPosition }; }, UPDATE_POSITION_MS); playing = false; }, TIMEOUT_100_MS); Script.setTimeout(function() { if (interval) { Script.clearInterval(interval); } }, TIMEOUT_10000_MS); } }, clickReleaseOnEntity: function(entityID, mouseEvent) { if (mouseEvent.isLeftButton) { this.playSound(); } } }; return new OrbRed(); });