Removed ParticleEmitterManager and merged changes into ParticleEmitter

This commit is contained in:
Richard Davey 2023-01-10 21:23:44 +00:00
parent 34f5e9522b
commit 891666e3cd
15 changed files with 398 additions and 5677 deletions

View file

@ -77,7 +77,7 @@ var GameObjects = {
Group: require('./group/GroupFactory'),
Image: require('./image/ImageFactory'),
Layer: require('./layer/LayerFactory'),
Particles: require('./particles/ParticleManagerFactory'),
Particles: require('./particles/ParticleEmitterFactory'),
PathFollower: require('./pathfollower/PathFollowerFactory'),
RenderTexture: require('./rendertexture/RenderTextureFactory'),
Rope: require('./rope/RopeFactory'),
@ -110,7 +110,7 @@ var GameObjects = {
Group: require('./group/GroupCreator'),
Image: require('./image/ImageCreator'),
Layer: require('./layer/LayerCreator'),
Particles: require('./particles/ParticleManagerCreator'),
Particles: require('./particles/ParticleEmitterCreator'),
RenderTexture: require('./rendertexture/RenderTextureCreator'),
Rope: require('./rope/RopeCreator'),
Sprite: require('./sprite/SpriteCreator'),

View file

@ -27,7 +27,7 @@ var Particle = new Class({
initialize:
function Particle (emitter)
function Particle2 (emitter)
{
/**
* The Emitter to which this Particle belongs.
@ -297,7 +297,7 @@ var Particle = new Class({
* @type {Phaser.Scene}
* @since 3.60.0
*/
this.scene = emitter.manager.scene;
this.scene = emitter.scene;
/**
* The Animation State component of this Particle.
@ -342,7 +342,7 @@ var Particle = new Class({
*/
emit: function (event, a1, a2, a3, a4, a5)
{
return this.emitter.manager.emit(event, a1, a2, a3, a4, a5);
return this.emitter.emit(event, a1, a2, a3, a4, a5);
},
/**

View file

@ -1,788 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var AnimationState = require('../../animations/AnimationState');
var Class = require('../../utils/Class');
var DegToRad = require('../../math/DegToRad');
var Rectangle = require('../../geom/rectangle/Rectangle');
var RotateAround = require('../../math/RotateAround');
var Vector2 = require('../../math/Vector2');
/**
* @classdesc
* A Particle is a simple Game Object controlled by a Particle Emitter and Manager, and rendered by the Manager.
* It uses its own lightweight physics system, and can interact only with its Emitter's bounds and zones.
*
* @class Particle
* @memberof Phaser.GameObjects.Particles
* @constructor
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter to which this Particle belongs.
*/
var Particle2 = new Class({
initialize:
function Particle2 (emitter)
{
/**
* The Emitter to which this Particle belongs.
*
* A Particle can only belong to a single Emitter and is created, updated and destroyed via it.
*
* @name Phaser.GameObjects.Particles.Particle#emitter
* @type {Phaser.GameObjects.Particles.ParticleEmitter}
* @since 3.0.0
*/
this.emitter = emitter;
/**
* The texture used to render this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#texture
* @type {Phaser.Textures.Texture}
* @default null
* @since 3.60.0
*/
this.texture = null;
/**
* The texture frame used to render this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#frame
* @type {Phaser.Textures.Frame}
* @default null
* @since 3.0.0
*/
this.frame = null;
/**
* The x coordinate of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#x
* @type {number}
* @default 0
* @since 3.0.0
*/
this.x = 0;
/**
* The y coordinate of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#y
* @type {number}
* @default 0
* @since 3.0.0
*/
this.y = 0;
/**
* The x velocity of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#velocityX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.velocityX = 0;
/**
* The y velocity of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#velocityY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.velocityY = 0;
/**
* The x acceleration of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#accelerationX
* @type {number}
* @default 0
* @since 3.0.0
*/
this.accelerationX = 0;
/**
* The y acceleration of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#accelerationY
* @type {number}
* @default 0
* @since 3.0.0
*/
this.accelerationY = 0;
/**
* The maximum horizontal velocity this Particle can travel at.
*
* @name Phaser.GameObjects.Particles.Particle#maxVelocityX
* @type {number}
* @default 10000
* @since 3.0.0
*/
this.maxVelocityX = 10000;
/**
* The maximum vertical velocity this Particle can travel at.
*
* @name Phaser.GameObjects.Particles.Particle#maxVelocityY
* @type {number}
* @default 10000
* @since 3.0.0
*/
this.maxVelocityY = 10000;
/**
* The bounciness, or restitution, of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#bounce
* @type {number}
* @default 0
* @since 3.0.0
*/
this.bounce = 0;
/**
* The horizontal scale of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#scaleX
* @type {number}
* @default 1
* @since 3.0.0
*/
this.scaleX = 1;
/**
* The vertical scale of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#scaleY
* @type {number}
* @default 1
* @since 3.0.0
*/
this.scaleY = 1;
/**
* The alpha value of this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#alpha
* @type {number}
* @default 1
* @since 3.0.0
*/
this.alpha = 1;
/**
* The angle of this Particle in degrees.
*
* @name Phaser.GameObjects.Particles.Particle#angle
* @type {number}
* @default 0
* @since 3.0.0
*/
this.angle = 0;
/**
* The angle of this Particle in radians.
*
* @name Phaser.GameObjects.Particles.Particle#rotation
* @type {number}
* @default 0
* @since 3.0.0
*/
this.rotation = 0;
/**
* The tint applied to this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#tint
* @type {number}
* @webglOnly
* @since 3.0.0
*/
this.tint = 0xffffff;
/**
* The lifespan of this Particle in ms.
*
* @name Phaser.GameObjects.Particles.Particle#life
* @type {number}
* @default 1000
* @since 3.0.0
*/
this.life = 1000;
/**
* The current life of this Particle in ms.
*
* @name Phaser.GameObjects.Particles.Particle#lifeCurrent
* @type {number}
* @default 1000
* @since 3.0.0
*/
this.lifeCurrent = 1000;
/**
* The delay applied to this Particle upon emission, in ms.
*
* @name Phaser.GameObjects.Particles.Particle#delayCurrent
* @type {number}
* @default 0
* @since 3.0.0
*/
this.delayCurrent = 0;
/**
* The normalized lifespan T value, where 0 is the start and 1 is the end.
*
* @name Phaser.GameObjects.Particles.Particle#lifeT
* @type {number}
* @default 0
* @since 3.0.0
*/
this.lifeT = 0;
/**
* The data used by the ease equation.
*
* @name Phaser.GameObjects.Particles.Particle#data
* @type {object}
* @since 3.0.0
*/
this.data = {
tint: { min: 0xffffff, max: 0xffffff },
alpha: { min: 1, max: 1 },
rotate: { min: 0, max: 0 },
scaleX: { min: 1, max: 1 },
scaleY: { min: 1, max: 1 },
x: { min: 0, max: 0 },
y: { min: 0, max: 0 },
accelerationX: { min: 0, max: 0 },
accelerationY: { min: 0, max: 0 },
maxVelocityX: { min: 0, max: 0 },
maxVelocityY: { min: 0, max: 0 },
moveToX: { min: 0, max: 0 },
moveToY: { min: 0, max: 0 },
bounce: { min: 0, max: 0 }
};
/**
* Interal private value.
*
* @name Phaser.GameObjects.Particles.Particle#isCropped
* @type {boolean}
* @private
* @readonly
* @since 3.60.0
*/
this.isCropped = false;
/**
* A reference to the Scene to which this Game Object belongs.
*
* Game Objects can only belong to one Scene.
*
* You should consider this property as being read-only. You cannot move a
* Game Object to another Scene by simply changing it.
*
* @name Phaser.GameObjects.Particles.Particle#scene
* @type {Phaser.Scene}
* @since 3.60.0
*/
this.scene = emitter.scene;
/**
* The Animation State component of this Particle.
*
* This component provides features to apply animations to this Particle.
* It is responsible for playing, loading, queuing animations for later playback,
* mixing between animations and setting the current animation frame to this Particle.
*
* @name Phaser.GameObjects.Particles.Particle#anims
* @type {Phaser.Animations.AnimationState}
* @since 3.60.0
*/
this.anims = new AnimationState(this);
/**
* A rectangle that holds the bounds of this Particle after a call to
* the `Particle.getBounds` method has been made.
*
* @name Phaser.GameObjects.Particles.Particle#bounds
* @type {Phaser.Geom.Rectangle}
* @since 3.60.0
*/
this.bounds = new Rectangle();
},
/**
* The Event Emitter proxy.
*
* Passes on all parameters to the `ParticleEmitterManager` to emit directly.
*
* @method Phaser.GameObjects.Particles.Particle#emit
* @since 3.60.0
*
* @param {(string|Symbol)} event - The event name.
* @param {any} [a1] - Optional argument 1.
* @param {any} [a2] - Optional argument 2.
* @param {any} [a3] - Optional argument 3.
* @param {any} [a4] - Optional argument 4.
* @param {any} [a5] - Optional argument 5.
*
* @return {boolean} `true` if the event had listeners, else `false`.
*/
emit: function (event, a1, a2, a3, a4, a5)
{
return this.emitter.emit(event, a1, a2, a3, a4, a5);
},
/**
* Checks to see if this Particle is alive and updating.
*
* @method Phaser.GameObjects.Particles.Particle#isAlive
* @since 3.0.0
*
* @return {boolean} `true` if this Particle is alive and updating, otherwise `false`.
*/
isAlive: function ()
{
return (this.lifeCurrent > 0);
},
/**
* Kills this particle. This sets the `lifeCurrent` value to 0, which forces
* the Particle to be removed the next time its parent Emitter runs an update.
*
* @method Phaser.GameObjects.Particles.Particle#kill
* @since 3.60.0
*/
kill: function ()
{
this.lifeCurrent = 0;
},
/**
* Sets the position of this particle to the given x/y coordinates.
*
* If the parameters are left undefined, it resets the particle back to 0x0.
*
* @method Phaser.GameObjects.Particles.Particle#setPosition
* @since 3.60.0
*
* @param {number} [x=0] - The x coordinate to set this Particle to.
* @param {number} [y=0] - The y coordinate to set this Particle to.
*/
setPosition: function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
this.x = x;
this.y = y;
},
/**
* Starts this Particle from the given coordinates.
*
* @method Phaser.GameObjects.Particles.Particle#fire
* @since 3.0.0
*
* @param {number} [x] - The x coordinate to launch this Particle from.
* @param {number} [y] - The y coordinate to launch this Particle from.
*/
fire: function (x, y)
{
var emitter = this.emitter;
var ops = emitter.ops;
var anim = emitter.getAnim();
if (anim)
{
this.anims.play(anim);
}
else
{
this.frame = emitter.getFrame();
this.texture = this.frame.texture;
}
if (!this.frame)
{
throw new Error('Particle has no texture frame');
}
// Updates particle.x and particle.y during this call
emitter.getEmitZone(this);
if (x === undefined)
{
this.x += ops.x.onEmit(this, 'x');
}
else if (ops.x.steps > 0)
{
// EmitterOp is stepped but x was forced (follower?) so use it
this.x += x + ops.x.onEmit(this, 'x');
}
else
{
this.x += x;
}
if (y === undefined)
{
this.y += ops.y.onEmit(this, 'y');
}
else if (ops.y.steps > 0)
{
// EmitterOp is stepped but y was forced (follower?) so use it
this.y += y + ops.y.onEmit(this, 'y');
}
else
{
this.y += y;
}
this.life = ops.lifespan.onEmit(this, 'lifespan');
this.lifeCurrent = this.life;
this.lifeT = 0;
var sx = ops.speedX.onEmit(this, 'speedX');
var sy = (ops.speedY.active) ? ops.speedY.onEmit(this, 'speedY') : sx;
if (emitter.radial)
{
var rad = DegToRad(ops.angle.onEmit(this, 'angle'));
this.velocityX = Math.cos(rad) * Math.abs(sx);
this.velocityY = Math.sin(rad) * Math.abs(sy);
}
else if (emitter.moveTo)
{
var mx = ops.moveToX.onEmit(this, 'moveToX');
var my = ops.moveToY.onEmit(this, 'moveToY');
var lifeS = this.life / 1000;
this.velocityX = (mx - this.x) / lifeS;
this.velocityY = (my - this.y) / lifeS;
}
else
{
this.velocityX = sx;
this.velocityY = sy;
}
if (emitter.acceleration)
{
this.accelerationX = ops.accelerationX.onEmit(this, 'accelerationX');
this.accelerationY = ops.accelerationY.onEmit(this, 'accelerationY');
}
this.maxVelocityX = ops.maxVelocityX.onEmit(this, 'maxVelocityX');
this.maxVelocityY = ops.maxVelocityY.onEmit(this, 'maxVelocityY');
this.delayCurrent = ops.delay.onEmit(this, 'delay');
this.scaleX = ops.scaleX.onEmit(this, 'scaleX');
this.scaleY = (ops.scaleY.active) ? ops.scaleY.onEmit(this, 'scaleY') : this.scaleX;
this.angle = ops.rotate.onEmit(this, 'rotate');
this.rotation = DegToRad(this.angle);
this.bounce = ops.bounce.onEmit(this, 'bounce');
this.alpha = ops.alpha.onEmit(this, 'alpha');
this.tint = ops.tint.onEmit(this, 'tint');
},
/**
* An internal method that calculates the velocity of the Particle.
*
* @method Phaser.GameObjects.Particles.Particle#computeVelocity
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter that is updating this Particle.
* @param {number} delta - The delta time in ms.
* @param {number} step - The delta value divided by 1000.
* @param {Phaser.GameObjects.Particles.ParticleProcessor[]} processors - An array of all active Particle Processors.
* @param {number} t - The current normalized lifetime of the particle, between 0 (birth) and 1 (death).
*/
computeVelocity: function (emitter, delta, step, processors, t)
{
var ops = emitter.ops;
var vx = this.velocityX;
var vy = this.velocityY;
var ax = ops.accelerationX.onUpdate(this, 'accelerationX', t, this.accelerationX);
var ay = ops.accelerationY.onUpdate(this, 'accelerationY', t, this.accelerationY);
var mx = ops.maxVelocityX.onUpdate(this, 'maxVelocityX', t, this.maxVelocityX);
var my = ops.maxVelocityY.onUpdate(this, 'maxVelocityY', t, this.maxVelocityY);
vx += (emitter.gravityX * step);
vy += (emitter.gravityY * step);
if (ax)
{
vx += (ax * step);
}
if (ay)
{
vy += (ay * step);
}
if (vx > mx)
{
vx = mx;
}
else if (vx < -mx)
{
vx = -mx;
}
if (vy > my)
{
vy = my;
}
else if (vy < -my)
{
vy = -my;
}
this.velocityX = vx;
this.velocityY = vy;
// Apply any additional processors
for (var i = 0; i < processors.length; i++)
{
processors[i].update(this, delta, step, t);
}
},
/**
* Checks if this Particle is still within the bounds defined by the given Emitter.
*
* If not, and depending on the Emitter collision flags, the Particle may either stop or rebound.
*
* @method Phaser.GameObjects.Particles.Particle#checkBounds
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter to check the bounds against.
*/
checkBounds: function (emitter)
{
var bounds = emitter.bounds;
var bounce = -this.bounce;
if (this.x < bounds.x && emitter.collideLeft)
{
this.x = bounds.x;
this.velocityX *= bounce;
}
else if (this.x > bounds.right && emitter.collideRight)
{
this.x = bounds.right;
this.velocityX *= bounce;
}
if (this.y < bounds.y && emitter.collideTop)
{
this.y = bounds.y;
this.velocityY *= bounce;
}
else if (this.y > bounds.bottom && emitter.collideBottom)
{
this.y = bounds.bottom;
this.velocityY *= bounce;
}
},
/**
* The main update method for this Particle.
*
* Updates its life values, computes the velocity and repositions the Particle.
*
* @method Phaser.GameObjects.Particles.Particle#update
* @since 3.0.0
*
* @param {number} delta - The delta time in ms.
* @param {number} step - The delta value divided by 1000.
* @param {Phaser.GameObjects.Particles.ParticleProcessor[]} processors - An array of all active Particle Processors.
*
* @return {boolean} Returns `true` if this Particle has now expired and should be removed, otherwise `false` if still active.
*/
update: function (delta, step, processors)
{
if (this.lifeCurrent === 0)
{
// Particle is dead via `Particle.kill` method.
return true;
}
if (this.delayCurrent > 0)
{
this.delayCurrent -= delta;
return false;
}
this.anims.update(0, delta);
var emitter = this.emitter;
var ops = emitter.ops;
// How far along in life is this particle? (t = 0 to 1)
var t = 1 - (this.lifeCurrent / this.life);
this.lifeT = t;
this.x = ops.x.onUpdate(this, 'x', t, this.x);
this.y = ops.y.onUpdate(this, 'y', t, this.y);
if (emitter.moveTo)
{
var mx = ops.moveToX.onUpdate(this, 'moveToX', t, emitter.moveToX);
var my = ops.moveToY.onUpdate(this, 'moveToY', t, emitter.moveToY);
var lifeS = this.lifeCurrent / 1000;
this.velocityX = (mx - this.x) / lifeS;
this.velocityY = (my - this.y) / lifeS;
}
this.computeVelocity(emitter, delta, step, processors, t);
this.x += this.velocityX * step;
this.y += this.velocityY * step;
if (emitter.bounds)
{
this.checkBounds(emitter);
}
if (emitter.getDeathZone(this))
{
this.lifeCurrent = 0;
// No need to go any further, particle has been killed
return true;
}
this.scaleX = ops.scaleX.onUpdate(this, 'scaleX', t, this.scaleX);
this.scaleY = this.scaleX;
if (ops.scaleY.active)
{
this.scaleY = ops.scaleY.onUpdate(this, 'scaleY', t, this.scaleY);
}
this.angle = ops.rotate.onUpdate(this, 'rotate', t, this.angle);
this.rotation = DegToRad(this.angle);
this.alpha = ops.alpha.onUpdate(this, 'alpha', t, this.alpha);
this.tint = ops.tint.onUpdate(this, 'tint', t, this.tint);
this.bounce = ops.bounce.onUpdate(this, 'bounce', t, this.bounce);
this.lifeCurrent -= delta;
return (this.lifeCurrent <= 0);
},
/**
* This is a NOOP method and does nothing when called.
*
* @method Phaser.GameObjects.Particles.Particle#setSizeToFrame
* @since 3.60.0
*/
setSizeToFrame: function ()
{
// NOOP
},
/**
* Gets the bounds of this particle as a Geometry Rectangle, factoring in any
* transforms of the parent emitter and anything else above it in the display list.
*
* Once calculated the bounds can be accessed via the `Particle.bounds` property.
*
* @method Phaser.GameObjects.Particles.Particle#getBounds
* @since 3.60.0
*
* @param {Phaser.GameObjects.Components.TransformMatrix} [matrix] - Optional transform matrix to apply to this particle.
*
* @return {Phaser.Geom.Rectangle} A Rectangle containing the transformed bounds of this particle.
*/
getBounds: function (matrix)
{
if (matrix === undefined) { matrix = this.emitter.getWorldTransformMatrix(); }
var sx = Math.abs(matrix.scaleX) * this.scaleX;
var sy = Math.abs(matrix.scaleY) * this.scaleY;
var x = this.x;
var y = this.y;
var rotation = this.rotation;
var width = (this.frame.width * sx) / 2;
var height = (this.frame.height * sy) / 2;
var bounds = this.bounds;
var topLeft = new Vector2(x - width, y - height);
var topRight = new Vector2(x + width, y - height);
var bottomLeft = new Vector2(x - width, y + height);
var bottomRight = new Vector2(x + width, y + height);
if (rotation !== 0)
{
RotateAround(topLeft, x, y, rotation);
RotateAround(topRight, x, y, rotation);
RotateAround(bottomLeft, x, y, rotation);
RotateAround(bottomRight, x, y, rotation);
}
matrix.transformPoint(topLeft.x, topLeft.y, topLeft);
matrix.transformPoint(topRight.x, topRight.y, topRight);
matrix.transformPoint(bottomLeft.x, bottomLeft.y, bottomLeft);
matrix.transformPoint(bottomRight.x, bottomRight.y, bottomRight);
bounds.x = Math.min(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x);
bounds.y = Math.min(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y);
bounds.width = Math.max(topLeft.x, topRight.x, bottomLeft.x, bottomRight.x) - bounds.x;
bounds.height = Math.max(topLeft.y, topRight.y, bottomLeft.y, bottomRight.y) - bounds.y;
return bounds;
},
/**
* Destroys this Particle.
*
* @method Phaser.GameObjects.Particles.Particle#destroy
* @since 3.60.0
*/
destroy: function ()
{
this.anims.destroy();
this.anims = null;
this.emitter = null;
this.texture = null;
this.frame = null;
this.scene = null;
}
});
module.exports = Particle2;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -17,17 +17,118 @@ var tempMatrix4 = new TransformMatrix();
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.Particles.EmitterManager#renderCanvas
* @since 3.0.0
* @method Phaser.GameObjects.Particles.Emitter#renderCanvas
* @since 3.60.0
* @private
*
* @param {Phaser.Renderer.Canvas.CanvasRenderer} renderer - A reference to the current active Canvas renderer.
* @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - The Game Object being rendered in this call.
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Game Object being rendered in this call.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
*/
var ParticleManagerCanvasRenderer = function (renderer, emitterManager, camera, parentMatrix)
var ParticleEmitterCanvasRenderer = function (renderer, emitter, camera, parentMatrix)
{
var camMatrix = tempMatrix1;
var calcMatrix = tempMatrix2;
var particleMatrix = tempMatrix3;
var managerMatrix = tempMatrix4;
if (parentMatrix)
{
managerMatrix.loadIdentity();
managerMatrix.multiply(parentMatrix);
managerMatrix.translate(emitter.x, emitter.y);
managerMatrix.rotate(emitter.rotation);
managerMatrix.scale(emitter.scaleX, emitter.scaleY);
}
else
{
managerMatrix.applyITRS(emitter.x, emitter.y, emitter.rotation, emitter.scaleX, emitter.scaleY);
}
var ctx = renderer.currentContext;
var roundPixels = camera.roundPixels;
var camerAlpha = camera.alpha;
var emitterAlpha = emitter.alpha;
var particles = emitter.alive;
var particleCount = particles.length;
var viewBounds = emitter.viewBounds;
if (!emitter.visible || particleCount === 0 || (viewBounds && !RectangleToRectangle(viewBounds, camera.worldView)))
{
return;
}
if (emitter.sortCallback)
{
emitter.depthSort();
}
camera.addToRenderList(emitter);
var scrollFactorX = emitter.scrollFactorX;
var scrollFactorY = emitter.scrollFactorY;
ctx.save();
ctx.globalCompositeOperation = renderer.blendModes[emitter.blendMode];
for (var i = 0; i < particleCount; i++)
{
var particle = particles[i];
var alpha = particle.alpha * emitterAlpha * camerAlpha;
if (alpha <= 0 || particle.scaleX === 0 || particle.scaleY === 0)
{
continue;
}
particleMatrix.applyITRS(particle.x, particle.y, particle.rotation, particle.scaleX, particle.scaleY);
camMatrix.copyFrom(camera.matrix);
camMatrix.multiplyWithOffset(managerMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
// Undo the camera scroll
particleMatrix.e = particle.x;
particleMatrix.f = particle.y;
// Multiply by the particle matrix, store result in calcMatrix
camMatrix.multiply(particleMatrix, calcMatrix);
var frame = particle.frame;
var cd = frame.canvasData;
if (cd.width > 0 && cd.height > 0)
{
var x = -(frame.halfWidth);
var y = -(frame.halfHeight);
ctx.globalAlpha = alpha;
ctx.save();
calcMatrix.setToContext(ctx);
if (roundPixels)
{
x = Math.round(x);
y = Math.round(y);
}
ctx.imageSmoothingEnabled = !frame.source.scaleMode;
ctx.drawImage(frame.source.image, cd.x, cd.y, cd.width, cd.height, x, y, cd.width, cd.height);
ctx.restore();
}
}
ctx.restore();
/*
var emitters = emitterManager.emitters.list;
var emittersLength = emitters.length;
@ -137,6 +238,7 @@ var ParticleManagerCanvasRenderer = function (renderer, emitterManager, camera,
ctx.restore();
}
*/
};
module.exports = ParticleManagerCanvasRenderer;
module.exports = ParticleEmitterCanvasRenderer;

View file

@ -7,10 +7,10 @@
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var GetFastValue = require('../../utils/object/GetFastValue');
var ParticleEmitterManager = require('./ParticleEmitterManager');
var ParticleEmitter = require('./ParticleEmitter');
/**
* Creates a new Particle Emitter Manager Game Object and returns it.
* Creates a new Particle Emitter Game Object and returns it.
*
* Note: This method will only be available if the Particles Game Object has been built into Phaser.
*
@ -20,7 +20,7 @@ var ParticleEmitterManager = require('./ParticleEmitterManager');
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterManagerConfig} config - The configuration object this Game Object will use to create itself.
* @param {boolean} [addToScene] - Add this Game Object to the Scene after creating it? If set this argument overrides the `add` property in the config object.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} The Game Object that was created.
* @return {Phaser.GameObjects.Particles.ParticleEmitter} The Game Object that was created.
*/
GameObjectCreator.register('particles', function (config, addToScene)
{
@ -31,7 +31,7 @@ GameObjectCreator.register('particles', function (config, addToScene)
var emitters = GetFastValue(config, 'emitters', null);
// frame is optional and can contain the emitters array or object if skipped
var manager = new ParticleEmitterManager(this.scene, key, frame, emitters);
var manager = new ParticleEmitter(this.scene, key, frame, emitters);
if (addToScene !== undefined)
{

View file

@ -0,0 +1,26 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var GameObjectFactory = require('../GameObjectFactory');
var ParticleEmitter = require('./ParticleEmitter');
/**
* Creates a new Particle Emitter Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Particles Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#particles
* @since 3.60.0
*
* @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig} [config] - Configuration settings for the Particle Emitter.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitter} The Game Object that was created.
*/
GameObjectFactory.register('particles', function (key, config)
{
return this.displayList.add(new ParticleEmitter(this.scene, key, config));
});

View file

@ -1,637 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var Class = require('../../utils/Class');
var Components = require('../components');
var GameObject = require('../GameObject');
var GravityWell = require('./GravityWell');
var List = require('../../structs/List');
var ParticleEmitter = require('./ParticleEmitter');
var Render = require('./ParticleManagerRender');
/**
* @classdesc
* A Particle Emitter Manager creates and controls {@link Phaser.GameObjects.Particles.ParticleEmitter Particle Emitters} and {@link Phaser.GameObjects.Particles.GravityWell Gravity Wells}.
*
* @class ParticleEmitterManager
* @extends Phaser.GameObjects.GameObject
* @memberof Phaser.GameObjects.Particles
* @constructor
* @since 3.0.0
*
* @extends Phaser.GameObjects.Components.AlphaSingle
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.FX
* @extends Phaser.GameObjects.Components.Mask
* @extends Phaser.GameObjects.Components.Pipeline
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Scene} scene - The Scene to which this Emitter Manager belongs.
* @param {string} [texture] - The key of the Texture this Emitter Manager will use to render particles, as stored in the Texture Manager.
* @param {(string|number)} [frame] - An optional frame from the Texture this Emitter Manager will use to render particles.
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig|Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]} [emitters] - Configuration settings for one or more emitters to create.
*/
var ParticleEmitterManager = new Class({
Extends: GameObject,
Mixins: [
Components.AlphaSingle,
Components.Depth,
Components.FX,
Components.Mask,
Components.Pipeline,
Components.Transform,
Components.Visible,
Render
],
initialize:
// frame is optional and can contain the emitters array or object if skipped
function ParticleEmitterManager (scene, texture, frame, emitters)
{
GameObject.call(this, scene, 'ParticleEmitterManager');
/**
* The blend mode applied to all emitters and particles.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#blendMode
* @type {number}
* @default -1
* @private
* @since 3.0.0
*/
this.blendMode = -1;
/**
* The time scale applied to all emitters and particles, affecting flow rate, lifespan, and movement.
* Values larger than 1 are faster than normal.
* This is multiplied with any timeScale set on each individual emitter.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#timeScale
* @type {number}
* @default 1
* @since 3.0.0
*/
this.timeScale = 1;
/**
* The texture used by all Particle Emitters, and by extension all Particles, that this Emitter Manager creates.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#texture
* @type {Phaser.Textures.Texture}
* @default null
* @since 3.0.0
*/
this.texture = null;
/**
* The texture frame used by all Particle Emitters, and by extension all Particles, that this Emitter Manager creates.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#frame
* @type {Phaser.Textures.Frame}
* @default null
* @since 3.0.0
*/
this.frame = null;
/**
* The names of all of Texture Frames this Particle Emitter Manager uses.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#frameNames
* @type {string[]}
* @since 3.0.0
*/
this.frameNames = [];
// frame is optional and can contain the emitters array or object if skipped
if (frame !== null && (typeof frame === 'object' || Array.isArray(frame)))
{
emitters = frame;
frame = null;
}
/**
* The names of all of animations this Particle Emitter Manager uses.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#animNames
* @type {string[]}
* @since 3.60.0
*/
this.animNames = [];
this.setTexture(texture, frame);
/**
* The default texture frame used by all Particle Emitters.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#defaultFrame
* @type {Phaser.Textures.Frame}
* @since 3.0.0
*/
this.defaultFrame = this.frame;
/**
* A list of Emitters being managed by this Emitter Manager.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#emitters
* @type {Phaser.Structs.List.<Phaser.GameObjects.Particles.ParticleEmitter>}
* @since 3.0.0
*/
this.emitters = new List(this);
/**
* A list of Particle Processors being managed by this Emitter Manager.
*
* @name Phaser.GameObjects.Particles.ParticleEmitterManager#processors
* @type {Phaser.Structs.List.<Phaser.GameObjects.Particles.ParticleProcessor>}
* @since 3.0.0
*/
this.processors = new List(this);
if (emitters)
{
// An array of emitter configs?
if (!Array.isArray(emitters))
{
emitters = [ emitters ];
}
for (var i = 0; i < emitters.length; i++)
{
this.createEmitter(emitters[i]);
}
}
this.initPipeline();
},
// Overrides Game Object method
addedToScene: function ()
{
this.scene.sys.updateList.add(this);
},
// Overrides Game Object method
removedFromScene: function ()
{
this.scene.sys.updateList.remove(this);
},
/**
* Sets the texture and frame this Emitter Manager will use to render with.
*
* Textures are referenced by their string-based keys, as stored in the Texture Manager.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setTexture
* @since 3.0.0
*
* @param {string} key - The key of the texture to be used, as stored in the Texture Manager.
* @param {(string|number)} [frame] - The name or index of the frame within the Texture.
*
* @return {this} This Emitter Manager.
*/
setTexture: function (key, frame)
{
this.texture = this.scene.sys.textures.get(key);
return this.setFrame(frame);
},
/**
* Sets the frame this Emitter Manager will use to render with.
*
* The Frame has to belong to the current Texture being used.
*
* It can be either a string or an index.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setFrame
* @since 3.0.0
*
* @param {(string|number)} [frame] - The name or index of the frame within the Texture.
*
* @return {this} This Emitter Manager.
*/
setFrame: function (frame)
{
this.frame = this.texture.get(frame);
var frames = this.texture.getFramesFromTextureSource(this.frame.sourceIndex);
var names = [];
frames.forEach(function (sourceFrame)
{
names.push(sourceFrame.name);
});
this.frameNames = names;
this.defaultFrame = this.frame;
this.animNames = this.scene.sys.anims.getAnimsFromTexture(this.texture);
if (this.animNames.length > 0)
{
this.defaultAnim = this.animNames[0];
}
return this;
},
/**
* Assigns texture frames to an emitter.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setEmitterFrames
* @since 3.0.0
*
* @param {(Phaser.Textures.Frame|Phaser.Textures.Frame[])} frames - The texture frames.
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The particle emitter to modify.
*
* @return {this} This Emitter Manager.
*/
setEmitterFrames: function (frames, emitter)
{
if (!Array.isArray(frames))
{
frames = [ frames ];
}
var out = emitter.frames;
out.length = 0;
for (var i = 0; i < frames.length; i++)
{
var frame = frames[i];
if (this.frameNames.indexOf(frame) !== -1)
{
out.push(this.texture.get(frame));
}
else
{
console.warn('Texture "%s" has no frame "%s"', this.texture.key, frame);
}
}
if (out.length > 0)
{
emitter.defaultFrame = out[0];
}
else
{
console.warn('No texture frames were set');
emitter.defaultFrame = this.defaultFrame;
}
return this;
},
/**
* Assigns texture frames to an emitter.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setEmitterAnims
* @since 3.60.0
*
* @param {(Phaser.Textures.Frame|Phaser.Textures.Frame[])} anims - The animations.
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The particle emitter to modify.
*
* @return {this} This Emitter Manager.
*/
setEmitterAnims: function (anims, emitter)
{
if (!Array.isArray(anims))
{
anims = [ anims ];
}
var out = emitter.anims;
out.length = 0;
for (var i = 0; i < anims.length; i++)
{
var anim = anims[i];
if (this.animNames.indexOf(anim) !== -1)
{
out.push(anim);
}
else
{
console.warn('Emitter has no animation "%s"', anim);
}
}
if (out.length > 0)
{
emitter.defaultAnim = out[0];
}
return this;
},
/**
* Adds an existing Particle Emitter to this Emitter Manager.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#addEmitter
* @since 3.0.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Particle Emitter to add to this Emitter Manager.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitter} The Particle Emitter that was added to this Emitter Manager.
*/
addEmitter: function (emitter)
{
return this.emitters.add(emitter);
},
/**
* Creates a new Particle Emitter object, adds it to this Emitter Manager and returns a reference to it.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#createEmitter
* @since 3.0.0
*
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig} config - Configuration settings for the Particle Emitter to create.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitter} The Particle Emitter that was created.
*/
createEmitter: function (config)
{
return this.addEmitter(new ParticleEmitter(this, config));
},
/**
* Removes a Particle Emitter from this Emitter Manager.
*
* The Emitter must belong to this Manager.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#removeEmitter
* @since 3.22.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Particle Emitter to remove from this Emitter Manager.
*
* @return {?Phaser.GameObjects.Particles.ParticleEmitter} The Particle Emitter that was removed, or null if it could not be found.
*/
removeEmitter: function (emitter)
{
return this.emitters.remove(emitter, true);
},
/**
* Adds a Particle Processor, such as a Gravity Well, to this Emitter Manager.
*
* It will start processing particles from the next update as long as its `active`
* property is set.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#addParticleProcessor
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.ParticleProcessor} processor - The Particle Processor to add to this Emitter Manager.
*
* @return {Phaser.GameObjects.Particles.ParticleProcessor} The Particle Processor that was added to this Emitter Manager.
*/
addParticleProcessor: function (processor)
{
if (!this.processors.exists(processor))
{
if (processor.manager)
{
processor.manager.removeParticleProcessor(processor);
}
this.processors.add(processor);
processor.manager = this;
}
return processor;
},
/**
* Removes a Particle Processor from this Emitter Manager.
*
* The Processor must belong to this Manager.
*
* It is not destroyed when removed, allowing you to move it to another Emitter Manager,
* so if you no longer require it you should call its `destroy` method directly.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#removeParticleProcessor
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.ParticleProcessor} processor - The Particle Processor to remove from this Emitter Manager.
*
* @return {?Phaser.GameObjects.Particles.ParticleProcessor} The Particle Processor that was removed, or null if it could not be found.
*/
removeParticleProcessor: function (processor)
{
if (this.processors.exists(processor))
{
this.processors.remove(processor, true);
processor.manager = null;
}
return processor;
},
/**
* Creates a new Gravity Well, adds it to this Emitter Manager and returns a reference to it.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#createGravityWell
* @since 3.0.0
*
* @param {Phaser.Types.GameObjects.Particles.GravityWellConfig} config - Configuration settings for the Gravity Well to create.
*
* @return {Phaser.GameObjects.Particles.GravityWell} The Gravity Well that was created.
*/
createGravityWell: function (config)
{
return this.addParticleProcessor(new GravityWell(config));
},
/**
* Emits particles from each active emitter.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#emitParticle
* @since 3.0.0
*
* @param {number} [count] - The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}.
* @param {number} [x] - The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location.
* @param {number} [y] - The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location.
*
* @return {this} This Emitter Manager.
*/
emitParticle: function (count, x, y)
{
var emitters = this.emitters.list;
for (var i = 0; i < emitters.length; i++)
{
var emitter = emitters[i];
if (emitter.active)
{
emitter.emitParticle(count, x, y);
}
}
return this;
},
/**
* Emits particles from each active emitter.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#emitParticleAt
* @since 3.0.0
*
* @param {number} [x] - The x-coordinate to to emit particles from. The default is the x-coordinate of the emitter's current location.
* @param {number} [y] - The y-coordinate to to emit particles from. The default is the y-coordinate of the emitter's current location.
* @param {number} [count] - The number of particles to release from each emitter. The default is the emitter's own {@link Phaser.GameObjects.Particles.ParticleEmitter#quantity}.
*
* @return {this} This Emitter Manager.
*/
emitParticleAt: function (x, y, count)
{
return this.emitParticle(count, x, y);
},
/**
* Pauses this Emitter Manager.
*
* This has the effect of pausing all emitters, and all particles of those emitters, currently under its control.
*
* The particles will still render, but they will not have any of their logic updated.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#pause
* @since 3.0.0
*
* @return {this} This Emitter Manager.
*/
pause: function ()
{
this.active = false;
return this;
},
/**
* Resumes this Emitter Manager, should it have been previously paused.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#resume
* @since 3.0.0
*
* @return {this} This Emitter Manager.
*/
resume: function ()
{
this.active = true;
return this;
},
/**
* Gets all active Particle Processors.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#getProcessors
* @since 3.0.0
*
* @return {Phaser.GameObjects.Particles.ParticleProcessor[]} - An array of active Particle Processors.
*/
getProcessors: function ()
{
return this.processors.getAll('active', true);
},
/**
* Updates all active emitters.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#preUpdate
* @since 3.0.0
*
* @param {number} time - The current timestamp as generated by the Request Animation Frame or SetTimeout.
* @param {number} delta - The delta time, in ms, elapsed since the last frame.
*/
preUpdate: function (time, delta)
{
if (this.active)
{
// Scale the delta
delta *= this.timeScale;
var emitters = this.emitters.list;
for (var i = 0; i < emitters.length; i++)
{
var emitter = emitters[i];
if (emitter.active)
{
emitter.preUpdate(time, delta);
}
}
}
},
/**
* A NOOP method so you can pass an EmitterManager to a Container.
* Calling this method will do nothing. It is intentionally empty.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setScrollFactor
* @private
* @since 3.10.0
*/
setScrollFactor: function ()
{
},
/**
* A NOOP method so you can pass an EmitterManager to a Container.
* Calling this method will do nothing. It is intentionally empty.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#setBlendMode
* @private
* @since 3.15.0
*/
setBlendMode: function ()
{
},
/**
* Handles the pre-destroy step for the Particle Emitter Manager, which destroys all emitters and processors.
*
* @method Phaser.GameObjects.Particles.ParticleEmitterManager#preDestroy
* @private
* @since 3.60.0
*/
preDestroy: function ()
{
var i;
var emitters = this.emitters.list;
var processors = this.processors.list;
for (i = 0; i < emitters.length; i++)
{
emitters[i].destroy();
}
for (i = 0; i < processors.length; i++)
{
processors[i].destroy();
}
this.frameNames = [];
this.defaultAnim = null;
this.defaultFrame = null;
}
});
module.exports = ParticleEmitterManager;

View file

@ -15,7 +15,7 @@ if (typeof WEBGL_RENDERER)
if (typeof CANVAS_RENDERER)
{
// renderCanvas = require('./ParticleManagerCanvasRenderer');
renderCanvas = require('./ParticleEmitterCanvasRenderer');
}
module.exports = {

View file

@ -18,12 +18,12 @@ var tempMatrix4 = new TransformMatrix();
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.Particles.EmitterManager#renderWebGL
* @since 3.0.0
* @method Phaser.GameObjects.Particles.Emitter#renderWebGL
* @since 3.60.0
* @private
*
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - The Game Object being rendered in this call.
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Game Object being rendered in this call.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
*/

View file

@ -1,33 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var GameObjectFactory = require('../GameObjectFactory');
var ParticleEmitterManager = require('./ParticleEmitterManager');
var ParticleEmitter2 = require('./ParticleEmitter2');
/**
* Creates a new Particle Emitter Manager Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Particles Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#particles
* @since 3.0.0
*
* @param {(string|Phaser.Textures.Texture)} texture - The key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
* @param {(string|number|object)} [frame] - An optional frame from the Texture this Game Object is rendering with.
* @param {Phaser.Types.GameObjects.Particles.ParticleEmitterConfig|Phaser.Types.GameObjects.Particles.ParticleEmitterConfig[]} [emitters] - Configuration settings for one or more emitters to create.
*
* @return {Phaser.GameObjects.Particles.ParticleEmitterManager} The Game Object that was created.
*/
GameObjectFactory.register('particles', function (key, frame, emitters)
{
return this.displayList.add(new ParticleEmitterManager(this.scene, key, frame, emitters));
});
GameObjectFactory.register('particles2', function (key, config)
{
return this.displayList.add(new ParticleEmitter2(this.scene, key, config));
});

View file

@ -1,26 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var NOOP = require('../../utils/NOOP');
var renderWebGL = NOOP;
var renderCanvas = NOOP;
if (typeof WEBGL_RENDERER)
{
renderWebGL = require('./ParticleManagerWebGLRenderer');
}
if (typeof CANVAS_RENDERER)
{
renderCanvas = require('./ParticleManagerCanvasRenderer');
}
module.exports = {
renderWebGL: renderWebGL,
renderCanvas: renderCanvas
};

View file

@ -1,149 +0,0 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2013-2023 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var RectangleToRectangle = require('../../geom/intersects/RectangleToRectangle');
var TransformMatrix = require('../components/TransformMatrix');
var Utils = require('../../renderer/webgl/Utils');
var tempMatrix1 = new TransformMatrix();
var tempMatrix2 = new TransformMatrix();
var tempMatrix3 = new TransformMatrix();
var tempMatrix4 = new TransformMatrix();
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.Particles.EmitterManager#renderWebGL
* @since 3.0.0
* @private
*
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.GameObjects.Particles.ParticleEmitterManager} emitterManager - The Game Object being rendered in this call.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
*/
var ParticleManagerWebGLRenderer = function (renderer, emitterManager, camera, parentMatrix)
{
var emitters = emitterManager.emitters.list;
var emittersLength = emitters.length;
if (emittersLength === 0)
{
return;
}
var pipeline = renderer.pipelines.set(emitterManager.pipeline);
var camMatrix = tempMatrix1;
var calcMatrix = tempMatrix2;
var particleMatrix = tempMatrix3;
var managerMatrix = tempMatrix4;
if (parentMatrix)
{
managerMatrix.loadIdentity();
managerMatrix.multiply(parentMatrix);
managerMatrix.translate(emitterManager.x, emitterManager.y);
managerMatrix.rotate(emitterManager.rotation);
managerMatrix.scale(emitterManager.scaleX, emitterManager.scaleY);
}
else
{
managerMatrix.applyITRS(emitterManager.x, emitterManager.y, emitterManager.rotation, emitterManager.scaleX, emitterManager.scaleY);
}
var roundPixels = camera.roundPixels;
var texture = emitterManager.defaultFrame.glTexture;
var getTint = Utils.getTintAppendFloatAlpha;
var camerAlpha = camera.alpha;
var managerAlpha = emitterManager.alpha;
renderer.pipelines.preBatch(emitterManager);
for (var e = 0; e < emittersLength; e++)
{
var emitter = emitters[e];
var particles = emitter.alive;
var particleCount = particles.length;
var viewBounds = emitter.viewBounds;
if (!emitter.visible || particleCount === 0 || (viewBounds && !RectangleToRectangle(viewBounds, camera.worldView)))
{
continue;
}
if (emitter.sortCallback)
{
emitter.depthSort();
}
var textureUnit = pipeline.setGameObject(emitter, emitter.defaultFrame);
camera.addToRenderList(emitter);
var scrollFactorX = emitter.scrollFactorX;
var scrollFactorY = emitter.scrollFactorY;
renderer.setBlendMode(emitter.blendMode);
if (emitter.mask)
{
emitter.mask.preRenderWebGL(renderer, emitter, camera);
renderer.pipelines.set(emitterManager.pipeline);
}
var tintEffect = 0;
for (var i = 0; i < particleCount; i++)
{
var particle = particles[i];
var alpha = particle.alpha * managerAlpha * camerAlpha;
if (alpha <= 0 || particle.scaleX === 0 || particle.scaleY === 0)
{
continue;
}
particleMatrix.applyITRS(particle.x, particle.y, particle.rotation, particle.scaleX, particle.scaleY);
camMatrix.copyFrom(camera.matrix);
camMatrix.multiplyWithOffset(managerMatrix, -camera.scrollX * scrollFactorX, -camera.scrollY * scrollFactorY);
// Undo the camera scroll
particleMatrix.e = particle.x;
particleMatrix.f = particle.y;
// Multiply by the particle matrix, store result in calcMatrix
camMatrix.multiply(particleMatrix, calcMatrix);
var frame = particle.frame;
var x = -frame.halfWidth;
var y = -frame.halfHeight;
var quad = calcMatrix.setQuad(x, y, x + frame.width, y + frame.height, roundPixels);
var tint = getTint(particle.tint, alpha);
pipeline.batchQuad(emitter, quad[0], quad[1], quad[2], quad[3], quad[4], quad[5], quad[6], quad[7], frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, tintEffect, texture, textureUnit);
}
if (emitter.mask)
{
emitter.mask.postRenderWebGL(renderer, camera);
}
}
renderer.pipelines.postBatch(emitterManager);
};
module.exports = ParticleManagerWebGLRenderer;

View file

@ -15,7 +15,6 @@ module.exports = {
GravityWell: require('./GravityWell'),
Particle: require('./Particle'),
ParticleEmitter: require('./ParticleEmitter'),
ParticleEmitterManager: require('./ParticleEmitterManager'),
ParticleProcessor: require('./ParticleProcessor'),
Zones: require('./zones')