You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 lines
841 B

  1. define([
  2. 'js/rendering/effects'
  3. ], function (
  4. effects
  5. ) {
  6. return {
  7. type: 'fadeInOut',
  8. delta: 1,
  9. updateCd: 0,
  10. updateCdMax: 10,
  11. alphaMax: 1,
  12. alphaMin: 0,
  13. infinite: false,
  14. init: function (blueprint) {
  15. if (this.obj.components.some(c => c.type === this.type))
  16. return true;
  17. },
  18. update: function () {
  19. let { updateCd, delta } = this;
  20. const { updateCdMax, alphaMin, alphaMax, infinite, obj: { sprite } } = this;
  21. updateCd += delta;
  22. if (updateCd === updateCdMax) {
  23. if (!infinite)
  24. this.destroyed = true;
  25. else
  26. delta *= -1;
  27. }
  28. this.updateCd = updateCd;
  29. this.delta = delta;
  30. if (!sprite)
  31. return;
  32. const alpha = alphaMin + ((updateCd / updateCdMax) * (alphaMax - alphaMin));
  33. sprite.alpha = alpha;
  34. },
  35. destroy: function () {
  36. effects.unregister(this);
  37. }
  38. };
  39. });