Guest User

Untitled

a guest
Jul 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. var PixiRenderer = function (_BaseRenderer) {
  2. inherits(PixiRenderer, _BaseRenderer);
  3.  
  4. function PixiRenderer(element, stroke) {
  5. classCallCheck(this, PixiRenderer);
  6.  
  7. var _this = possibleConstructorReturn(this, (PixiRenderer.__proto__ || Object.getPrototypeOf(PixiRenderer)).call(this, element));
  8.  
  9. _this.stroke = stroke;
  10. _this.setColor = false;
  11. _this.pool.create = function (body, particle) {
  12. return _this.createBody(body, particle);
  13. };
  14. _this.name = 'PixiRenderer';
  15. return _this;
  16. }
  17.  
  18. createClass(PixiRenderer, [{
  19. key: 'onProtonUpdate',
  20. value: function onProtonUpdate() {}
  21.  
  22. /**
  23. * @param particle
  24. */
  25.  
  26. }, {
  27. key: 'onParticleCreated',
  28. value: function onParticleCreated(particle) {
  29. if (particle.body) {
  30. particle.body = this.pool.get(particle.body, particle);
  31. } else {
  32. particle.body = this.pool.get(this.circleConf, particle);
  33. }
  34.  
  35. this.element.addChild(particle.body);
  36. }
  37.  
  38. /**
  39. * @param particle
  40. */
  41.  
  42. }, {
  43. key: 'onParticleUpdate',
  44. value: function onParticleUpdate(particle) {
  45. this.transform(particle, particle.body);
  46. if (this.setColor) particle.body.tint = ColorUtil.getHex16FromParticle(particle);
  47. }
  48.  
  49. /**
  50. * @param particle
  51. */
  52.  
  53. }, {
  54. key: 'onParticleDead',
  55. value: function onParticleDead(particle) {
  56. this.element.removeChild(particle.body);
  57. this.pool.expire(particle.body);
  58. particle.body = null;
  59. }
  60. }, {
  61. key: 'destroy',
  62. value: function destroy(particles) {
  63. get(PixiRenderer.prototype.__proto__ || Object.getPrototypeOf(PixiRenderer.prototype), 'destroy', this).call(this);
  64. this.pool.destroy();
  65.  
  66. var i = particles.length;
  67. while (i--) {
  68. var particle = particles[i];
  69. if (particle.body) {
  70. this.element.removeChild(particle.body);
  71. }
  72. }
  73. }
  74. }, {
  75. key: 'transform',
  76. value: function transform(particle, target) {
  77. target.x = particle.p.x;
  78. target.y = particle.p.y;
  79.  
  80. target.alpha = particle.alpha;
  81.  
  82. target.scale.x = particle.scale;
  83. target.scale.y = particle.scale;
  84.  
  85. // using cached version of MathUtils.PI_180 for slight performance increase.
  86. target.rotation = particle.rotation * MathUtils.PI_180; // MathUtils.PI_180;
  87. }
  88. }, {
  89. key: 'createBody',
  90. value: function createBody(body, particle) {
  91. if (body.isCircle) return this.createCircle(particle);else return this.createSprite(body);
  92. }
  93. }, {
  94. key: 'createSprite',
  95. value: function createSprite(body) {
  96. var sprite = body.isInner ? PIXI.Sprite.fromImage(body.src) : new PIXI.Sprite(body);
  97. sprite.anchor.x = 0.5;
  98. sprite.anchor.y = 0.5;
  99.  
  100. return sprite;
  101. }
  102. }, {
  103. key: 'createCircle',
  104. value: function createCircle(particle) {
  105. var graphics = new PIXI.Graphics();
  106.  
  107. if (this.stroke) {
  108. var stroke = this.stroke instanceof String ? this.stroke : 0x000000;
  109. graphics.beginStroke(stroke);
  110. }
  111.  
  112. graphics.beginFill(particle.color || 0x008ced);
  113. graphics.drawCircle(0, 0, particle.radius);
  114. graphics.endFill();
  115.  
  116. return graphics;
  117. }
  118. }]);
  119. return PixiRenderer;
  120. }(BaseRenderer);
  121.  
  122. var MStack = function () {
  123. function MStack() {
  124. classCallCheck(this, MStack);
  125.  
  126. this.mats = [];
  127. this.size = 0;
  128.  
  129. for (var i = 0; i < 20; i++) {
  130. this.mats.push(Mat3.create([0, 0, 0, 0, 0, 0, 0, 0, 0]));
  131. }
  132. }
  133.  
  134. createClass(MStack, [{
  135. key: 'set',
  136. value: function set$$1(m, i) {
  137. if (i === 0) Mat3.set(m, this.mats[0]);else Mat3.multiply(this.mats[i - 1], m, this.mats[i]);
  138.  
  139. this.size = Math.max(this.size, i + 1);
  140. }
  141. }, {
  142. key: 'push',
  143. value: function push(m) {
  144. if (this.size === 0) Mat3.set(m, this.mats[0]);else Mat3.multiply(this.mats[this.size - 1], m, this.mats[this.size]);
  145.  
  146. this.size++;
  147. }
  148. }, {
  149. key: 'pop',
  150. value: function pop() {
  151. if (this.size > 0) this.size--;
  152. }
  153. }, {
  154. key: 'top',
  155. value: function top() {
  156. return this.mats[this.size - 1];
  157. }
  158. }]);
  159. return MStack;
  160. }();
Add Comment
Please, Sign In to add comment