From a18364e85ff73411d349e1acc1b524fa7ece1357 Mon Sep 17 00:00:00 2001 From: "Diego F. Goberna" Date: Wed, 3 Oct 2018 02:43:59 +0200 Subject: [PATCH] hide logo when playing --- src/components/logoflicker.js | 16 +++++++++++++--- src/templates/stage.html | 7 ++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/components/logoflicker.js b/src/components/logoflicker.js index 13e2c1c..f2a1f4a 100644 --- a/src/components/logoflicker.js +++ b/src/components/logoflicker.js @@ -3,11 +3,13 @@ AFRAME.registerComponent('logoflicker', { schema: { delay: {default: 1000.0}, + active: {default: true} }, init: function () { this.setOff = this.setOff.bind(this); this.setOn = this.setOn.bind(this); + this.timeout = 0; this.sparks = document.getElementById('logosparks'); this.sparkPositions = [ @@ -15,8 +17,16 @@ AFRAME.registerComponent('logoflicker', { {position: new THREE.Vector3(0.3, 0.8, 0)}, {position: new THREE.Vector3(-0.3, 0.8, 0)} ]; + }, - this.setOn(); + update: function (oldData) { + if (this.data.active !== oldData.active){ + if (this.data.active) { + this.setOn(); + } else { + clearTimeout(this.timeout); + } + } }, setOff: function () { @@ -25,13 +35,13 @@ AFRAME.registerComponent('logoflicker', { this.sparkPositions[Math.floor(Math.random() * this.sparkPositions.length)], false); - setTimeout(this.setOn, + this.timeout = setTimeout(this.setOn, 50 + Math.floor(Math.random() * 100)); }, setOn: function () { this.el.object3D.visible = true; - setTimeout(this.setOff, + this.timeout = setTimeout(this.setOff, Math.floor((this.data.delay * 3 / 10) + Math.random() * this.data.delay)); } }); diff --git a/src/templates/stage.html b/src/templates/stage.html index 1e8335b..b72722b 100644 --- a/src/templates/stage.html +++ b/src/templates/stage.html @@ -57,11 +57,12 @@ position="0 6 0" light="type: spot; penumbra: 1; intensity: 5; angle: 20" animation="property: rotation; from: 0 50 0; to: 0 -50 0; dur:300; easing: linear; startEvents: audioanalyser-beat"> - -