您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

108 行
1.9 KiB

  1. define([
  2. 'js/rendering/renderer',
  3. 'js/system/events'
  4. ], function(
  5. renderer,
  6. events
  7. ) {
  8. var scale = 40;
  9. var scaleMult = 5;
  10. var round = Math.round.bind(Math);
  11. return {
  12. type: 'pather',
  13. path: [],
  14. pathColor: '0x48edff',
  15. pathAlpha: 0.2,
  16. pathPos: {
  17. x: 0,
  18. y: 0
  19. },
  20. lastX: 0,
  21. lastY: 0,
  22. init: function() {
  23. events.on('onDeath', this.onDeath.bind(this));
  24. events.on('onClearQueue', this.onDeath.bind(this));
  25. this.pathPos.x = round(this.obj.x);
  26. this.pathPos.y = round(this.obj.y);
  27. },
  28. clearPath: function() {
  29. this.path.forEach(function(p) {
  30. renderer.destroyObject({
  31. layerName: 'effects',
  32. sprite: p.sprite
  33. });
  34. });
  35. this.path = [];
  36. },
  37. onDeath: function() {
  38. this.clearPath();
  39. this.pathPos.x = round(this.obj.x);
  40. this.pathPos.y = round(this.obj.y);
  41. },
  42. add: function(x, y) {
  43. this.path.push({
  44. x: x,
  45. y: y,
  46. sprite: renderer.buildRectangle({
  47. layerName: 'effects',
  48. color: this.pathColor,
  49. alpha: this.pathAlpha,
  50. x: (x * scale) + scaleMult,
  51. y: (y * scale) + scaleMult,
  52. w: scale - (scaleMult * 2),
  53. h: scale - (scaleMult * 2)
  54. })
  55. });
  56. },
  57. update: function() {
  58. var x = this.obj.x;
  59. var y = this.obj.y;
  60. if (this.path.length == 0) {
  61. this.pathPos.x = round(x);
  62. this.pathPos.y = round(y);
  63. }
  64. if ((x == this.lastX) && (y == this.lastY))
  65. return;
  66. this.lastX = x;
  67. this.lastY = y;
  68. for (var i = 0; i < this.path.length; i++) {
  69. var p = this.path[i];
  70. if ((p.x == x) && (p.y == y)) {
  71. for (var j = 0; j <= i; j++) {
  72. renderer.destroyObject({
  73. layerName: 'effects',
  74. sprite: this.path[j].sprite
  75. });
  76. }
  77. this.path.splice(0, i + 1);
  78. return;
  79. }
  80. }
  81. },
  82. setPath: function(path) {
  83. this.path = this.path.concat(path);
  84. this.pathPos.x = round(path[path.length - 1].x);
  85. this.pathPos.y = round(path[path.length - 1].y);
  86. }
  87. };
  88. });