score text fade in

This commit is contained in:
Kevin Ngo
2018-10-15 17:18:39 -07:00
parent 2549857cc1
commit b70ae20b10
2 changed files with 56 additions and 7 deletions

View File

@@ -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;
}
}
}
});