From 93220c3b01c065e326b12b5932a46c929db3bb30 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Tue, 2 Feb 2016 10:51:10 -0800 Subject: [PATCH] two sounds --- .../ACAudioSearchAndInject.js | 11 ++--- .../acAudioSearchCompatibleEntitySpawner.js | 45 ++++++++++++++----- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js b/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js index dee5408589..3356942b8a 100644 --- a/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js +++ b/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js @@ -25,7 +25,9 @@ EntityViewer.setKeyholeRadius(60000); EntityViewer.queryOctree(); Entities.setPacketsPerSecond(6000); -Script.setInterval(function() { +Script.setInterval(searchForSoundEntities, 1000); + +function searchForSoundEntities() { var entities = Entities.findEntities({ x: 0, y: 0, @@ -33,13 +35,12 @@ Script.setInterval(function() { }, 16000) print("EBL ENTITIES FOUND " + entities.length); entities.forEach(function(entity) { - var soundData = getEntityCustomData(SOUND_KEY, entity); + var soundData = getEntityCustomData(SOUND_DATA_KEY, entity); if (soundData && soundData.url) { playSound(soundData); } }); - -}, 1000); +} function playSound(soundData) { var sound = SoundCache.getSound(soundData.url); @@ -52,7 +53,7 @@ function playSound(soundData) { z: 0 }, volume: 1.0, - loop: true + loop: false }); }) diff --git a/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js b/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js index e25e114ba5..328e2d3cf6 100644 --- a/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js +++ b/examples/audioExamples/acAudioSearching/acAudioSearchCompatibleEntitySpawner.js @@ -5,7 +5,7 @@ // Created by Eric Levin 2/2/2016 // Copyright 2016 High Fidelity, Inc. -// This is a client script which spawns entities with a field in userdata compatible with the AcAudioSearchAndInject script +// This is a client script which spawns entities with a field in userData compatible with the AcAudioSearchAndInject script // These entities specify data about the sound they want to play, such as url, volume, and whether to loop or not // The position of the entity determines the position from which the sound plays from // @@ -17,20 +17,41 @@ Script.include("../../libraries/utils.js"); var SOUND_DATA_KEY = "soundKey"; -var soundEntity = Entities.addEntity({ +var userData = { + soundKey: { + url: "http://hifi-public.s3.amazonaws.com/ryan/Water_Lap_River_Edge_Gentle.L.wav" + } +} + +var entityProps = { type: "Box", - position: {x: 0, y: 0, z: 0}, - color: {red: 200, green: 10, blue: 200}, - dimensions: {x: .1, y: .1, z: .1}, - userData: JSON.stringify({ - soundKey: { - url: "http://hifi-public.s3.amazonaws.com/ryan/demo/0619_Fireplace__Tree_B.L.wav" - } - }) -}); + position: { + x: 0, + y: 0, + z: 0 + }, + color: { + red: 200, + green: 10, + blue: 200 + }, + dimensions: { + x: .1, + y: .1, + z: .1 + }, + userData: JSON.stringify(userData) +} +var soundEntity1 = Entities.addEntity(entityProps); + +userData.soundKey.url = "http://hifi-public.s3.amazonaws.com/ryan/demo/0619_Fireplace__Tree_B.L.wav"; +entityProps.userData = JSON.stringify(userData); +entityProps.position.x += 0.3 +var soundEntity2 = Entities.addEntity(entityProps); function cleanup() { - Entities.deleteEntity(soundEntity); + Entities.deleteEntity(soundEntity1); + Entities.deleteEntity(soundEntity2); } Script.scriptEnding.connect(cleanup); \ No newline at end of file