2017-10-17 03:19:03 +00:00
|
|
|
var GameObject = require('../GameObject');
|
|
|
|
|
|
|
|
var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpolationPercentage, camera)
|
|
|
|
{
|
2017-10-20 13:14:37 +00:00
|
|
|
var emitters = emitterManager.emitters.list;
|
2017-10-17 03:19:03 +00:00
|
|
|
|
|
|
|
if (emitters.length === 0 || GameObject.RENDER_MASK !== emitterManager.renderFlags || (emitterManager.cameraFilter > 0 && (emitterManager.cameraFilter & camera._id)))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < emitters.length; i++)
|
|
|
|
{
|
|
|
|
var emitter = emitters[i];
|
|
|
|
|
|
|
|
var particles = emitter.alive;
|
|
|
|
var length = particles.length;
|
|
|
|
|
2017-10-19 23:54:28 +00:00
|
|
|
if (!emitter.visible || length === 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var ctx = renderer.currentContext;
|
2017-10-17 03:19:03 +00:00
|
|
|
|
|
|
|
var lastAlpha = ctx.globalAlpha;
|
|
|
|
var cameraScrollX = camera.scrollX * emitter.scrollFactorX;
|
|
|
|
var cameraScrollY = camera.scrollY * emitter.scrollFactorY;
|
|
|
|
|
|
|
|
if (renderer.currentBlendMode !== emitter.blendMode)
|
|
|
|
{
|
|
|
|
renderer.currentBlendMode = emitter.blendMode;
|
|
|
|
ctx.globalCompositeOperation = renderer.blendModes[emitter.blendMode];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var index = 0; index < length; ++index)
|
|
|
|
{
|
|
|
|
var particle = particles[index];
|
2017-10-19 23:54:28 +00:00
|
|
|
|
2017-11-11 03:51:54 +00:00
|
|
|
var alpha = ((particle.color >> 24) & 0xFF) / 255.0;
|
|
|
|
|
|
|
|
if (alpha <= 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-10-19 23:54:28 +00:00
|
|
|
var frame = particle.frame;
|
|
|
|
var width = frame.width;
|
|
|
|
var height = frame.height;
|
|
|
|
var ox = width * 0.5;
|
|
|
|
var oy = height * 0.5;
|
|
|
|
var cd = frame.canvasData;
|
|
|
|
|
2017-10-17 03:19:03 +00:00
|
|
|
var x = -ox;
|
|
|
|
var y = -oy;
|
|
|
|
|
|
|
|
ctx.globalAlpha = alpha;
|
|
|
|
|
|
|
|
ctx.save();
|
|
|
|
ctx.translate(particle.x - cameraScrollX * particle.scrollFactorX, particle.y - cameraScrollY * particle.scrollFactorY);
|
|
|
|
ctx.rotate(particle.rotation);
|
|
|
|
ctx.scale(particle.scaleX, particle.scaleY);
|
|
|
|
ctx.drawImage(frame.source.image, cd.sx, cd.sy, cd.sWidth, cd.sHeight, x, y, cd.dWidth, cd.dHeight);
|
|
|
|
ctx.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.globalAlpha = lastAlpha;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ParticleManagerCanvasRenderer;
|