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.
 
 
 

57 lines
1.2 KiB

  1. define([
  2. 'js/rendering/renderer'
  3. ], function (
  4. renderer
  5. ) {
  6. return {
  7. type: 'particles',
  8. emitter: null,
  9. init: function (blueprint) {
  10. this.blueprint = this.blueprint || {};
  11. this.blueprint.pos = {
  12. x: (this.obj.x * scale) + (scale / 2),
  13. y: (this.obj.y * scale) + (scale / 2)
  14. };
  15. this.ttl = blueprint.ttl;
  16. this.blueprint.obj = this.obj;
  17. this.emitter = renderer.buildEmitter(this.blueprint);
  18. this.setVisible(this.obj.isVisible);
  19. },
  20. setVisible: function (visible) {
  21. //Sometimes, we make emitters stop emitting for a reason
  22. // for example, when an explosion stops
  23. if (!this.emitter.disabled)
  24. this.emitter.emit = visible;
  25. },
  26. update: function () {
  27. const { ttl, destroyObject, emitter, obj } = this;
  28. if (ttl !== null) {
  29. this.ttl--;
  30. if (this.ttl <= 0) {
  31. if (destroyObject)
  32. this.obj.destroyed = true;
  33. else
  34. this.destroyed = true;
  35. return;
  36. }
  37. }
  38. if (!emitter.emit)
  39. return;
  40. emitter.spawnPos.x = (obj.x * scale) + (scale / 2) + obj.offsetX;
  41. emitter.spawnPos.y = (obj.y * scale) + (scale / 2) + obj.offsetY;
  42. },
  43. destroy: function () {
  44. renderer.destroyEmitter(this.emitter);
  45. }
  46. };
  47. });