Skip to content

Instantly share code, notes, and snippets.

@scummtomte
Created Jul 19, 2018
Embed
What would you like to do?
var PixiRenderer = function (_BaseRenderer) {
inherits(PixiRenderer, _BaseRenderer);
function PixiRenderer(element, stroke) {
classCallCheck(this, PixiRenderer);
var _this = possibleConstructorReturn(this, (PixiRenderer.__proto__ || Object.getPrototypeOf(PixiRenderer)).call(this, element));
_this.stroke = stroke;
_this.setColor = false;
_this.pool.create = function (body, particle) {
return _this.createBody(body, particle);
};
_this.name = 'PixiRenderer';
return _this;
}
createClass(PixiRenderer, [{
key: 'onProtonUpdate',
value: function onProtonUpdate() {}
/**
* @param particle
*/
}, {
key: 'onParticleCreated',
value: function onParticleCreated(particle) {
if (particle.body) {
particle.body = this.pool.get(particle.body, particle);
} else {
particle.body = this.pool.get(this.circleConf, particle);
}
this.element.addChild(particle.body);
}
/**
* @param particle
*/
}, {
key: 'onParticleUpdate',
value: function onParticleUpdate(particle) {
this.transform(particle, particle.body);
if (this.setColor) particle.body.tint = ColorUtil.getHex16FromParticle(particle);
}
/**
* @param particle
*/
}, {
key: 'onParticleDead',
value: function onParticleDead(particle) {
this.element.removeChild(particle.body);
this.pool.expire(particle.body);
particle.body = null;
}
}, {
key: 'destroy',
value: function destroy(particles) {
get(PixiRenderer.prototype.__proto__ || Object.getPrototypeOf(PixiRenderer.prototype), 'destroy', this).call(this);
this.pool.destroy();
var i = particles.length;
while (i--) {
var particle = particles[i];
if (particle.body) {
this.element.removeChild(particle.body);
}
}
}
}, {
key: 'transform',
value: function transform(particle, target) {
target.x = particle.p.x;
target.y = particle.p.y;
target.alpha = particle.alpha;
target.scale.x = particle.scale;
target.scale.y = particle.scale;
// using cached version of MathUtils.PI_180 for slight performance increase.
target.rotation = particle.rotation * MathUtils.PI_180; // MathUtils.PI_180;
}
}, {
key: 'createBody',
value: function createBody(body, particle) {
if (body.isCircle) return this.createCircle(particle);else return this.createSprite(body);
}
}, {
key: 'createSprite',
value: function createSprite(body) {
var sprite = body.isInner ? PIXI.Sprite.fromImage(body.src) : new PIXI.Sprite(body);
sprite.anchor.x = 0.5;
sprite.anchor.y = 0.5;
return sprite;
}
}, {
key: 'createCircle',
value: function createCircle(particle) {
var graphics = new PIXI.Graphics();
if (this.stroke) {
var stroke = this.stroke instanceof String ? this.stroke : 0x000000;
graphics.beginStroke(stroke);
}
graphics.beginFill(particle.color || 0x008ced);
graphics.drawCircle(0, 0, particle.radius);
graphics.endFill();
return graphics;
}
}]);
return PixiRenderer;
}(BaseRenderer);
var MStack = function () {
function MStack() {
classCallCheck(this, MStack);
this.mats = [];
this.size = 0;
for (var i = 0; i < 20; i++) {
this.mats.push(Mat3.create([0, 0, 0, 0, 0, 0, 0, 0, 0]));
}
}
createClass(MStack, [{
key: 'set',
value: function set$$1(m, i) {
if (i === 0) Mat3.set(m, this.mats[0]);else Mat3.multiply(this.mats[i - 1], m, this.mats[i]);
this.size = Math.max(this.size, i + 1);
}
}, {
key: 'push',
value: function push(m) {
if (this.size === 0) Mat3.set(m, this.mats[0]);else Mat3.multiply(this.mats[this.size - 1], m, this.mats[this.size]);
this.size++;
}
}, {
key: 'pop',
value: function pop() {
if (this.size > 0) this.size--;
}
}, {
key: 'top',
value: function top() {
return this.mats[this.size - 1];
}
}]);
return MStack;
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment