reduce delay between hit and hearing sound (trimmed audio file more, got rid of event

This commit is contained in:
Kevin Ngo
2018-10-12 00:40:22 -07:00
parent 62dd94e571
commit c7feccf133
4 changed files with 11 additions and 13 deletions

Binary file not shown.

View File

@@ -29,22 +29,18 @@ THREE.Audio.prototype.play = function () {
/**
* Beat hit sound using positional audio and audio buffer source.
* Pitch the sound up and down using the song audioanalyser FFT.
*/
AFRAME.registerComponent('beat-hit', {
AFRAME.registerComponent('beat-hit-sound', {
dependencies: ['sound__beathit'],
init: function () {
const data = this.data;
const el = this.el;
this.processSound = this.processSound.bind(this);
},
const soundPool = el.components.sound__beathit;
el.addEventListener('beathit', evt => {
this.currentBeatEl = evt.detail;
soundPool.playSound(this.processSound);
});
playSound: function (beatEl) {
const soundPool = this.el.components.sound__beathit;
this.currentBeatEl = beatEl;
soundPool.playSound(this.processSound);
},
processSound: function (audio) {

View File

@@ -421,12 +421,14 @@ AFRAME.registerComponent('beat', {
saberBoundingBox = saberEls[i].components['saber-controls'].boundingBox;
if (!boundingBox || !saberBoundingBox) { break; }
if (saberBoundingBox.intersectsBox(boundingBox)) {
this.el.emit('beathit', this.el);
this.el.emit('beathit', null, false);
this.el.parentNode.components['beat-hit-sound'].playSound(this.el);
this.destroyBeat(saberEls[i]);
break;
}
if (saberBoundingBox.intersectsBox(beatBoundingBox)) {
this.el.emit('beathit', this.el);
this.el.emit('beathit', null, false);
this.el.parentNode.components['beat-hit-sound'].playSound(this.el);
this.destroyBeat(saberEls[i]);
this.wrongCut(saberEls[i].getAttribute('saber-controls').hand);
break;

View File

@@ -106,7 +106,7 @@
<a-entity id="container">
<a-entity
id="beatContainer"
beat-hit
beat-hit-sound
bind__pause="isPaused: !isPlaying"
sound__beathit="poolSize: 12; src: assets/sounds/beatHit.ogg"></a-entity>
{% include './templates/stage.html' %}