pause logic (not yet resume logic)
This commit is contained in:
@@ -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;
|
||||
|
||||
16
src/components/beat-pauser.js
Normal file
16
src/components/beat-pauser.js
Normal 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
13
src/components/pause.js
Normal 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user