Testing Emitter2 stand-alone

This commit is contained in:
Richard Davey 2023-01-09 18:12:19 +00:00
parent fffd2bcb04
commit b5e9cc9a7b
5 changed files with 1017 additions and 20 deletions

View file

@ -0,0 +1,788 @@
/**
* @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;

View file

@ -5,7 +5,6 @@
*/
var Add = require('../../utils/array/Add');
var BlendModes = require('../../renderer/BlendModes');
var Class = require('../../utils/Class');
var Components = require('../components');
var CopyFrom = require('../../geom/rectangle/CopyFrom');
@ -20,7 +19,7 @@ var HasAny = require('../../utils/object/HasAny');
var HasValue = require('../../utils/object/HasValue');
var Inflate = require('../../geom/rectangle/Inflate');
var MergeRect = require('../../geom/rectangle/MergeRect');
var Particle = require('./Particle');
var Particle2 = require('./Particle2');
var RandomZone = require('./zones/RandomZone');
var Rectangle = require('../../geom/rectangle/Rectangle');
var RectangleToRectangle = require('../../geom/intersects/RectangleToRectangle');
@ -30,6 +29,7 @@ var StableSort = require('../../utils/array/StableSort');
var TransformMatrix = require('../components/TransformMatrix');
var Vector2 = require('../../math/Vector2');
var Wrap = require('../../math/Wrap');
var List = require('../../structs/List');
/**
* Names of simple configuration properties.
@ -56,7 +56,7 @@ var configFastMap = [
'maxAliveParticles',
'maxParticles',
'name',
'on',
'emitting',
'particleBringToTop',
'particleClass',
'radial',
@ -316,7 +316,7 @@ var ParticleEmitter2 = new Class({
initialize:
function ParticleEmitter2 (scene, config)
function ParticleEmitter2 (scene, texture, config)
{
GameObject.call(this, scene, 'ParticleEmitter');
@ -329,7 +329,7 @@ var ParticleEmitter2 = new Class({
* @since 3.0.0
* @see Phaser.Types.GameObjects.Particles.ParticleClassConstructor
*/
this.particleClass = Particle;
this.particleClass = Particle2;
/**
* An internal object holding all of the EmitterOp instances.
@ -933,9 +933,47 @@ var ParticleEmitter2 = new Class({
*/
this.sortCallback = this.depthSortCallback;
/**
* 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);
this.setTexture(texture);
this.initPipeline();
this.fromJSON(config);
},
// Overrides Game Object method
addedToScene: function ()
{
this.scene.sys.updateList.add(this);
},
// Overrides Game Object method
removedFromScene: function ()
{
this.scene.sys.updateList.remove(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);
},
/**
* Merges configuration settings into the emitter's current settings.
*
@ -1054,7 +1092,7 @@ var ParticleEmitter2 = new Class({
if (this.emitting)
{
this.manager.emit(Events.START, this);
this.emit(Events.START, this);
}
return this;
@ -1191,6 +1229,9 @@ var ParticleEmitter2 = new Class({
*/
getFrame: function ()
{
return this.frame;
/*
if (this.frames.length === 1)
{
return this.defaultFrame;
@ -1213,6 +1254,7 @@ var ParticleEmitter2 = new Class({
return frame;
}
*/
},
/**
@ -1232,7 +1274,6 @@ var ParticleEmitter2 = new Class({
* @param {number} [quantity=1] - The number of consecutive particles that will receive each frame.
*
* @return {this} This Particle Emitter.
*/
setFrame: function (frames, pickRandom, quantity)
{
if (pickRandom === undefined) { pickRandom = true; }
@ -1276,6 +1317,7 @@ var ParticleEmitter2 = new Class({
return this;
},
*/
/**
* Chooses an animation from {@link Phaser.GameObjects.Particles.ParticleEmitter#anims}, if populated.
@ -1950,7 +1992,7 @@ var ParticleEmitter2 = new Class({
{
if (zones[i].willKill(particle))
{
this.manager.emit(Events.DEATH_ZONE, this, particle, zones[i]);
this.emit(Events.DEATH_ZONE, this, particle, zones[i]);
return true;
}
@ -2267,7 +2309,7 @@ var ParticleEmitter2 = new Class({
this.duration = Math.abs(duration);
}
this.manager.emit(Events.START, this);
this.emit(Events.START, this);
}
return this;
@ -2302,7 +2344,7 @@ var ParticleEmitter2 = new Class({
this.killAll();
}
this.manager.emit(Events.STOP, this);
this.emit(Events.STOP, this);
}
return this;
@ -2348,13 +2390,13 @@ var ParticleEmitter2 = new Class({
* @since 3.22.0
*
* @return {this} This Particle Emitter.
*/
remove: function ()
{
this.manager.removeEmitter(this);
return this;
},
*/
/**
* Set the property by which active particles are sorted prior to be rendered.
@ -2520,7 +2562,7 @@ var ParticleEmitter2 = new Class({
var particle = this.emitParticle(count, x, y);
this.manager.emit(Events.EXPLODE, this, particle);
this.emit(Events.EXPLODE, this, particle);
return particle;
},
@ -2684,7 +2726,7 @@ var ParticleEmitter2 = new Class({
}
// Any particle processors?
var processors = this.manager.getProcessors();
var processors = this.getProcessors();
var particles = this.alive;
var dead = this.dead;
@ -2741,7 +2783,7 @@ var ParticleEmitter2 = new Class({
// completeFlag
counters[5] = 0;
this.manager.emit(Events.COMPLETE, this);
this.emit(Events.COMPLETE, this);
}
return;
@ -2797,7 +2839,6 @@ var ParticleEmitter2 = new Class({
* @param {Phaser.GameObjects.Components.TransformMatrix} [parentMatrix] - A temporary matrix to hold parent values during the calculations.
*
* @return {Phaser.GameObjects.Components.TransformMatrix} The populated Transform Matrix.
*/
getWorldTransformMatrix: function (tempMatrix, parentMatrix)
{
if (tempMatrix === undefined) { tempMatrix = this.tempMatrix1; }
@ -2818,6 +2859,7 @@ var ParticleEmitter2 = new Class({
return tempMatrix;
},
*/
/**
* Takes either a Rectangle Geometry object or an Arcade Physics Body and tests
@ -3602,14 +3644,13 @@ var ParticleEmitter2 = new Class({
/**
* Destroys this Particle Emitter and all Particles it owns.
*
* @method Phaser.GameObjects.Particles.ParticleEmitter#destroy
* @method Phaser.GameObjects.Particles.ParticleEmitter#preDestroy
* @since 3.60.0
*/
destroy: function ()
preDestroy: function ()
{
this.manager = null;
this.texture = null;
this.frames = null;
// this.texture = null;
// this.frames = null;
this.anims = null;
this.defaultFrame = null;
this.emitCallback = null;

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 NOOP = require('../../utils/NOOP');
var renderWebGL = NOOP;
var renderCanvas = NOOP;
if (typeof WEBGL_RENDERER)
{
renderWebGL = require('./ParticleEmitterWebGLRenderer');
}
if (typeof CANVAS_RENDERER)
{
// renderCanvas = require('./ParticleManagerCanvasRenderer');
}
module.exports = {
renderWebGL: renderWebGL,
renderCanvas: renderCanvas
};

View file

@ -0,0 +1,136 @@
/**
* @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 ParticleEmitterWebGLRenderer = function (renderer, emitter, camera, parentMatrix)
{
var pipeline = renderer.pipelines.set(emitter.pipeline);
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 roundPixels = camera.roundPixels;
var getTint = Utils.getTintAppendFloatAlpha;
var camerAlpha = camera.alpha;
var emitterAlpha = emitter.alpha;
var texture = emitter.texture.glTexture;
renderer.pipelines.preBatch(emitter);
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();
}
var textureUnit = pipeline.setGameObject(emitter, emitter.frame);
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(emitter.pipeline);
}
var tintEffect = 0;
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 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(emitter);
};
module.exports = ParticleEmitterWebGLRenderer;

View file

@ -6,6 +6,7 @@
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.
@ -25,3 +26,8 @@ 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));
});