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.
 
 
 

85 lines
1.6 KiB

  1. define([
  2. 'particles',
  3. 'js/rendering/particleDefaults',
  4. 'js/rendering/shaders/outline'
  5. ], function (
  6. pixiParticles,
  7. particleDefaults,
  8. shaderOutline
  9. ) {
  10. return {
  11. renderer: null,
  12. stage: null,
  13. emitters: [],
  14. lastTick: null,
  15. init: function (options) {
  16. this.r = options.r;
  17. this.renderer = options.renderer;
  18. this.stage = options.stage;
  19. this.lastTick = Date.now();
  20. },
  21. buildEmitter: function (config) {
  22. let options = $.extend(true, {}, particleDefaults, config);
  23. let emitter = new PIXI.particles.Emitter(this.r.layers.particles, ['images/particles.png'], options);
  24. emitter.emit = true;
  25. this.emitters.push(emitter);
  26. return emitter;
  27. },
  28. destroyEmitter: function (emitter) {
  29. emitter.emit = false;
  30. },
  31. update: function () {
  32. let renderer = this.r;
  33. let now = Date.now();
  34. let emitters = this.emitters;
  35. let eLen = emitters.length;
  36. for (let i = 0; i < eLen; i++) {
  37. var e = emitters[i];
  38. let visible = null;
  39. let destroy = !e.emit;
  40. if (destroy) {
  41. if (e.particleCount > 0) {
  42. visible = renderer.isVisible(e.spawnPos.x, e.spawnPos.y);
  43. if (visible)
  44. destroy = false;
  45. }
  46. }
  47. if (destroy) {
  48. emitters.splice(i, 1);
  49. e.destroy();
  50. e = null;
  51. i--;
  52. eLen--;
  53. continue;
  54. }
  55. if (visible === null)
  56. visible = renderer.isVisible(e.spawnPos.x, e.spawnPos.y);
  57. if (!visible)
  58. continue;
  59. let r = e.update((now - this.lastTick) * 0.001);
  60. r.forEach(function (rr) {
  61. if (e.blendMode == 'overlay')
  62. rr.pluginName = 'picture';
  63. }, this);
  64. }
  65. this.lastTick = now;
  66. }
  67. };
  68. });