From a92fd1db3db0de7e3d540a4bcdeef0f1ac92e1a7 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 12 Nov 2018 17:49:12 +0800 Subject: [PATCH] add back beat hit sound pool hack --- src/components/beat-hit-sound.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/beat-hit-sound.js b/src/components/beat-hit-sound.js index 4c5076c..882d781 100644 --- a/src/components/beat-hit-sound.js +++ b/src/components/beat-hit-sound.js @@ -53,9 +53,8 @@ AFRAME.registerComponent('beat-hit-sound', { this.currentCutDirection = ''; this.processSound = this.processSound.bind(this); sourceCreatedCallback = this.sourceCreatedCallback.bind(this); - }, - play: function () { + // Sound pools. for (let i = 1; i <= 10; i++) { this.el.setAttribute(`sound__beathit${i}`, { poolSize: 4, @@ -72,6 +71,24 @@ AFRAME.registerComponent('beat-hit-sound', { } }, + play: function () { + // Kick three.js loader...Don't know why sometimes doesn't load. + for (let i = 1; i <= 10; i++) { + if (!this.el.components[`sound__beathit${i}`].loaded) { + this.el.setAttribute(`sound__beathit${i}`, 'src', ''); + this.el.setAttribute(`sound__beathit${i}`, 'src', `#hitSound${i}`); + } + if (!this.el.components[`sound__beathit${i}left`].loaded) { + this.el.setAttribute(`sound__beathit${i}left`, 'src', ''); + this.el.setAttribute(`sound__beathit${i}left`, 'src', `#hitSound${i}left`); + } + if (!this.el.components[`sound__beathit${i}right`].loaded) { + this.el.setAttribute(`sound__beathit${i}right`, 'src', ''); + this.el.setAttribute(`sound__beathit${i}right`, 'src', `#hitSound${i}right`); + } + } + }, + playSound: function (beatEl, cutDirection) { const rand = 1 + Math.floor(Math.random() * 10); const dir = this.directionsToSounds[cutDirection || 'up'];