reset beatOffsetTime on clearBeats
This commit is contained in:
@@ -139,7 +139,8 @@ AFRAME.registerComponent('beat-loader', {
|
||||
// Re-sync song with beats playback.
|
||||
const songComponent = this.el.components.song;
|
||||
const currentTime = songComponent.getCurrentTime();
|
||||
if (songComponent.songStartTime && this.beatsTimeOffset !== undefined &&
|
||||
|
||||
if (currentTime !== undefined && this.beatsTimeOffset !== undefined &&
|
||||
this.songCurrentTime !== currentTime) {
|
||||
this.songCurrentTime = currentTime;
|
||||
this.beatsTime = (this.songCurrentTime + this.data.beatAnticipationTime) * 1000;
|
||||
@@ -175,6 +176,7 @@ AFRAME.registerComponent('beat-loader', {
|
||||
}
|
||||
}
|
||||
|
||||
// Update preload beat offset.
|
||||
if (this.beatsTimeOffset !== undefined) {
|
||||
if (this.beatsTimeOffset <= 0) {
|
||||
this.el.sceneEl.emit('beatloaderpreloadfinish', null, false);
|
||||
@@ -185,7 +187,7 @@ AFRAME.registerComponent('beat-loader', {
|
||||
}
|
||||
}
|
||||
|
||||
this.beatsTime = beatsTime + delta;
|
||||
this.beatsTime += delta;
|
||||
},
|
||||
|
||||
generateBeat: (function () {
|
||||
@@ -302,7 +304,7 @@ AFRAME.registerComponent('beat-loader', {
|
||||
*/
|
||||
clearBeats: function () {
|
||||
this.beatsTime = 0;
|
||||
this.beatsTimeOffset = undefined;
|
||||
this.beatsTimeOffset = this.data.beatAnticipationTime * 1000;
|
||||
for (let i = 0; i < this.beatContainer.children.length; i++) {
|
||||
let child = this.beatContainer.children[i];
|
||||
if (child.components.beat) {
|
||||
|
||||
@@ -132,6 +132,7 @@ AFRAME.registerComponent('song', {
|
||||
this.source.stop();
|
||||
this.source.disconnect();
|
||||
this.source = null;
|
||||
this.songStartTime = undefined;
|
||||
},
|
||||
|
||||
victory: function () {
|
||||
@@ -178,6 +179,7 @@ AFRAME.registerComponent('song', {
|
||||
if (this.data.isBeatsPreloaded) { this.startAudio(); }
|
||||
}, ONCE);
|
||||
this.audioAnalyser.refreshSource();
|
||||
this.songStartTime = undefined;
|
||||
},
|
||||
|
||||
onWallHitStart: function () {
|
||||
@@ -200,6 +202,7 @@ AFRAME.registerComponent('song', {
|
||||
},
|
||||
|
||||
getCurrentTime: function () {
|
||||
if (this.songStartTime === undefined) { return undefined; }
|
||||
return this.context.currentTime - this.songStartTime;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user