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.
 
 
 

83 lines
1.5 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function (
  4. renderer
  5. ) {
  6. return {
  7. type: 'flash',
  8. color: '#48edff',
  9. filter: null,
  10. lum: -1,
  11. lumDir: 0.075,
  12. state: 0,
  13. maxState: 0,
  14. frame: 1,
  15. oldTexture: null,
  16. init: function () {
  17. //Destroy self
  18. if (!this.obj.sprite)
  19. return true;
  20. this.oldTexture = this.obj.sprite.texture;
  21. renderer.setSprite({
  22. sprite: this.obj.sprite,
  23. cell: 8 + this.frame,
  24. sheetName: 'animChar'
  25. });
  26. this.maxState = ((Math.abs(this.lum) / this.lumDir) + (Math.abs(this.lum) / (this.lumDir))) / 5;
  27. },
  28. getColor: function () {
  29. let hex = String(this.color).replace(/[^0-9a-f]/gi, '');
  30. if (hex.length < 6)
  31. hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
  32. let rgb = '#';
  33. let c = 0;
  34. for (let i = 0; i < 3; i++) {
  35. c = parseInt(hex.substr(i * 2, 2), 16);
  36. c = Math.round(Math.min(Math.max(0, c + (c * this.lum)), 255)).toString(16);
  37. rgb += ('00' + c).substr(c.length);
  38. }
  39. return rgb.replace('#', '0x');
  40. },
  41. update: function () {
  42. this.state++;
  43. if (this.state >= this.maxState) {
  44. this.state = 0;
  45. this.frame++;
  46. if (this.frame <= 5) {
  47. renderer.setSprite({
  48. sprite: this.obj.sprite,
  49. cell: 8 + this.frame,
  50. sheetName: 'animChar'
  51. });
  52. }
  53. }
  54. this.lum += this.lumDir;
  55. if ((this.lumDir > 0) && (this.lum >= 0))
  56. this.lumDir = -Math.abs(this.lumDir);
  57. else if ((this.lumDir <= 0) && (this.lum <= -1))
  58. this.destroyed = true;
  59. },
  60. destroy: function () {
  61. this.obj.sprite.texture = this.oldTexture;
  62. }
  63. };
  64. });