From b70ae20b1087b03bf83bc58f48bb9a263cd0e723 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 15 Oct 2018 17:18:39 -0700 Subject: [PATCH] score text fade in --- src/components/score-texts.js | 40 +++++++++++++++++++++++++++++++++++ src/templates/score.html | 23 ++++++++++++++------ 2 files changed, 56 insertions(+), 7 deletions(-) create mode 100644 src/components/score-texts.js diff --git a/src/components/score-texts.js b/src/components/score-texts.js new file mode 100644 index 0000000..0729de0 --- /dev/null +++ b/src/components/score-texts.js @@ -0,0 +1,40 @@ +/** + * Score text fade in animation. + */ +AFRAME.registerComponent('score-texts', { + dependencies: { + isSongLoading: {default: false} + }, + + init: function () { + this.textEls = this.el.querySelectorAll('[text]'); + + for (let i = 0; i < this.textEls.length; i++) { + this.textEls[i].setAttribute('animation__fadein', { + autoplay: false, + property:'components.text.material.uniforms.opacity.value', + delay: 250, + dur: 750, + easing: 'easeInOutCubic', + from: 0, + to: 1 + }); + } + }, + + update: function (oldData) { + // Finished loading. + if (oldData.isSongLoading && !this.data.isSongLoading) { + for (let i = 0; i < this.textEls.length; i++) { + this.textEls[i].components['animation__fadein'].beginAnimation(); + } + } + + // Started loading. + if (!oldData.isSongLoading && this.data.isSongLoading) { + for (let i = 0; i < this.textEls.length; i++) { + this.textEls[i].components.text.material.uniforms.opacity.value = 0; + } + } + } +}); diff --git a/src/templates/score.html b/src/templates/score.html index a892857..e34574d 100644 --- a/src/templates/score.html +++ b/src/templates/score.html @@ -1,28 +1,37 @@ + + - + + + +