From ce329e6505c42f757db20b192937cb9a50a0d848 Mon Sep 17 00:00:00 2001 From: William Toohey Date: Fri, 11 Nov 2016 15:31:44 +1000 Subject: [PATCH] Fix fast trippy crashing colours --- src/js/HuesCanvas.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/js/HuesCanvas.js b/src/js/HuesCanvas.js index dcbb93c..33bfe82 100644 --- a/src/js/HuesCanvas.js +++ b/src/js/HuesCanvas.js @@ -28,7 +28,8 @@ class HuesCanvas { constructor(root, soundManager, core) { this.audio = soundManager; - soundManager.addEventListener("seek", this.onSeek.bind(this)); + soundManager.addEventListener("seek", this.resetEffects.bind(this)); + core.addEventListener("newsong", this.resetEffects.bind(this)); core.addEventListener("newimage", this.setImage.bind(this)); core.addEventListener("newcolour", this.setColour.bind(this)); core.addEventListener("beat", this.beat.bind(this)); @@ -117,7 +118,7 @@ class HuesCanvas { this.trippyOn = localStorage["trippyMode"] == "on"; } - onSeek() { + resetEffects() { this.colourFadeStart = 0; this.colourFade = false; this.trippyStart = [0, 0]; @@ -380,8 +381,9 @@ class HuesCanvas { } this.needsRedraw = true; } - if(this.trippyStart[0] || this.trippyStart[1]) { - for(let i = 0; i < 2; i++) { + for(let i = 0; i < 2; i++) { + if(this.trippyStart[i] || this.trippyRadii[i]) { + this.needsRedraw = true; this.trippyRadii[i] = Math.floor((this.audio.currentTime - this.trippyStart[i]) * this.trippyRadius) * 2; if(this.trippyRadii[i] > this.trippyRadius) { this.trippyStart[i] = 0; @@ -393,7 +395,6 @@ class HuesCanvas { this.trippyRadii[i] = this.trippyRadius - this.trippyRadii[i]; } } - this.needsRedraw = true; } if(this.blurStart && this.blurDistance < 1) {