Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

84 rader
1.6 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. console.log(this.animation);
  21. this.oldTexture = this.obj.sprite.texture;
  22. renderer.setSprite({
  23. sprite: this.obj.sprite,
  24. cell: 8 + this.frame,
  25. sheetName: 'animChar'
  26. });
  27. this.maxState = ((Math.abs(this.lum) / this.lumDir) + (Math.abs(this.lum) / (this.lumDir))) / 5;
  28. },
  29. getColor: function() {
  30. var hex = String(this.color).replace(/[^0-9a-f]/gi, '');
  31. if (hex.length < 6)
  32. hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
  33. var rgb = '#';
  34. var c = 0;
  35. for (var i = 0; i < 3; i++) {
  36. c = parseInt(hex.substr(i * 2, 2), 16);
  37. c = Math.round(Math.min(Math.max(0, c + (c * this.lum)), 255)).toString(16);
  38. rgb += ('00' + c).substr(c.length);
  39. }
  40. return rgb.replace('#', '0x');
  41. },
  42. update: function() {
  43. this.state++;
  44. if (this.state >= this.maxState) {
  45. this.state = 0;
  46. this.frame++;
  47. if (this.frame <= 5) {
  48. renderer.setSprite({
  49. sprite: this.obj.sprite,
  50. cell: 8 + this.frame,
  51. sheetName: 'animChar'
  52. });
  53. }
  54. }
  55. this.lum += this.lumDir;
  56. if ((this.lumDir > 0) && (this.lum >= 0))
  57. this.lumDir = -Math.abs(this.lumDir);
  58. else if ((this.lumDir <= 0) && (this.lum <= -1))
  59. this.destroyed = true;
  60. },
  61. destroy: function() {
  62. this.obj.sprite.texture = this.oldTexture;
  63. }
  64. };
  65. });