The add and remove processes can set the manager property.

This commit is contained in:
Richard Davey 2023-01-03 21:45:29 +00:00
parent d78df08412
commit ada620b522
3 changed files with 34 additions and 9 deletions

View file

@ -36,7 +36,7 @@ var GravityWell = new Class({
initialize:
function GravityWell (manager, x, y, power, epsilon, gravity)
function GravityWell (x, y, power, epsilon, gravity)
{
if (typeof x === 'object')
{
@ -57,7 +57,7 @@ var GravityWell = new Class({
if (gravity === undefined) { gravity = 50; }
}
ParticleProcessor.call(this, manager, x, y, true);
ParticleProcessor.call(this, x, y, true);
/**
* Internal gravity value.

View file

@ -388,6 +388,9 @@ var ParticleEmitterManager = new Class({
/**
* 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
*
@ -397,7 +400,19 @@ var ParticleEmitterManager = new Class({
*/
addParticleProcessor: function (processor)
{
return this.processors.add(processor);
if (!this.processors.exists(processor))
{
if (processor.manager)
{
processor.manager.removeParticleProcessor(processor);
}
this.processors.add(processor);
processor.manager = this;
}
return processor;
},
/**
@ -405,6 +420,9 @@ var ParticleEmitterManager = new Class({
*
* 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
*
@ -414,7 +432,14 @@ var ParticleEmitterManager = new Class({
*/
removeParticleProcessor: function (processor)
{
return this.processors.remove(processor, true);
if (this.processors.exists(processor))
{
this.processors.remove(processor, true);
processor.manager = null;
}
return processor;
},
/**
@ -429,7 +454,7 @@ var ParticleEmitterManager = new Class({
*/
createGravityWell: function (config)
{
return this.addParticleProcessor(new GravityWell(this, config));
return this.addParticleProcessor(new GravityWell(config));
},
/**

View file

@ -20,7 +20,6 @@ var Class = require('../../utils/Class');
* @constructor
* @since 3.60.0
*
* @param {Phaser.GameObjects.Particles.ParticleEmitterManager} manager - A reference to the Particle Emitter Manager that owns this Processor.
* @param {number} [x=0] - The x coordinate of the Particle Processor, in world space.
* @param {number} [y=0] - The y coordinate of the Particle Processor, in world space.
* @param {boolean} [active=true] - The active state of this Particle Processor.
@ -29,7 +28,7 @@ var ParticleProcessor = new Class({
initialize:
function ParticleProcessor (manager, x, y, active)
function ParticleProcessor (x, y, active)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
@ -37,13 +36,14 @@ var ParticleProcessor = new Class({
/**
* A reference to the Particle Emitter Manager that owns this
* Processor.
* Processor. This is set automatically when the Processor is
* added to an Emitter Manager, and nulled when removed or destroyed.
*
* @name Phaser.GameObjects.Particles.ParticleProcessor#manager
* @type {Phaser.GameObjects.Particles.ParticleEmitterManager}
* @since 3.60.0
*/
this.manager = manager;
this.manager;
/**
* The x coordinate of the Particle Processor, in world space.