pause logic (not yet resume logic)

This commit is contained in:
Kevin Ngo
2018-10-03 18:58:26 -07:00
parent 9392e57133
commit e9c6c4a9f0
7 changed files with 58 additions and 23 deletions

View File

@@ -8,7 +8,8 @@ AFRAME.registerComponent('beat-loader', {
beatAnticipationTime: {default: 2.0},
beatSpeed: {default: 4.0},
challengeId: {type: 'string'},
difficulty: {type: 'string'}
difficulty: {type: 'string'},
isPaused: {default: false}
},
orientations: [180, 0, 270, 90, 225, 135, 315, 45, 0],
@@ -53,6 +54,9 @@ AFRAME.registerComponent('beat-loader', {
console.log('Finished loading challenge data.');
},
/**
* Generate beats and stuff according to timestamp.
*/
tick: function (time, delta) {
var audioEl = this.el.components.song.audio;
var i;
@@ -62,7 +66,7 @@ AFRAME.registerComponent('beat-loader', {
var msPerBeat;
var noteTime;
if (!this.data.challengeId || !this.beatData || !audioEl) { return; }
if (this.data.isPaused || !this.data.challengeId || !this.beatData || !audioEl) { return; }
notes = this.beatData._notes;
obstacles = this.beatData._obstacles;

View File

@@ -0,0 +1,16 @@
/**
* 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();
}
}
});

13
src/components/pause.js Normal file
View File

@@ -0,0 +1,13 @@
AFRAME.registerComponent('pause', {
schema: {
isPaused: {default: false}
},
update: function () {
if (this.data.isPaused && this.el.isPlaying) {
this.el.pause();
} else if (!this.data.isPaused && !this.el.isPlaying && this.el.sceneEl.isPlaying) {
this.el.play();
}
}
});

View File

@@ -30,7 +30,7 @@ AFRAME.registerComponent('song', {
}
// Keep playback state up to date.
if ((data.isPlaying && data.challengeId) && this.audio.paused) {
if (data.isPlaying && data.challengeId && this.audio.paused) {
console.log(`Playing ${this.audio.src}...`);
this.data.analyserEl.setAttribute('audioanalyser', 'src', audio);
audio.play();