hook up pause menu actions (resume, restart, exit), but still need to force beats to reposition off audio.currentTime

This commit is contained in:
Kevin Ngo
2018-10-04 00:20:45 -07:00
parent 0a773559e5
commit 733741012b
6 changed files with 50 additions and 33 deletions

View File

@@ -1,16 +0,0 @@
/**
* Pause all beats.
*/
AFRAME.registerComponent('beat-pauser', {
pause: function () {
for (let i = 0; i < this.el.children.length; i++) {
this.el.children[i].pause();
}
},
play: function () {
for (let i = 0; i < this.el.children.length; i++) {
this.el.children[i].play();
}
}
});

View File

@@ -1,7 +1,8 @@
AFRAME.registerComponent('saber-controls', {
schema: {
bladeEnabled: {default: false},
hand: {default: 'right', oneOf: ['left', 'right']}
hand: {default: 'right', oneOf: ['left', 'right']},
isPaused: {default: false}
},
init: function () {
@@ -24,6 +25,9 @@ AFRAME.registerComponent('saber-controls', {
update: function (oldData) {
if (!oldData.bladeEnabled && this.data.bladeEnabled) {
this.bladeEl.emit('drawblade');
if (!oldData.isPaused) {
this.bladeEl.emit('drawbladesound');
}
}
},

View File

@@ -12,10 +12,17 @@ AFRAME.registerComponent('song', {
init: function () {
// Use audio element for audioanalyser.
this.audio = document.createElement('audio');
this.audio.setAttribute('id', 'song');
this.audio.crossOrigin = 'anonymous';
this.el.sceneEl.appendChild(this.audio);
const audio = this.audio = document.createElement('audio');
audio.setAttribute('id', 'song');
audio.crossOrigin = 'anonymous';
this.el.sceneEl.appendChild(audio);
this.el.addEventListener('pausemenurestart', () => {
if (audio.paused) {
audio.currentTime = 0;
audio.play();
}
});
},
update: function (oldData) {