2017-10-17 03:16:08 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-10-17 20:32:45 +00:00
|
|
|
var DegToRad = require('../../math/DegToRad');
|
2017-10-27 20:19:30 +00:00
|
|
|
var DistanceBetween = require('../../math/distance/DistanceBetween');
|
2017-10-17 03:16:08 +00:00
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2018-02-06 22:25:23 +00:00
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @class Particle
|
|
|
|
* @memberOf Phaser.GameObjects.Particles
|
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter to which this Particle belongs.
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
var Particle = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-10-21 04:05:51 +00:00
|
|
|
function Particle (emitter)
|
2017-10-17 03:16:08 +00:00
|
|
|
{
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2017-10-21 04:05:51 +00:00
|
|
|
this.emitter = emitter;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#frame
|
|
|
|
* @type {Phaser.Texture.Frame}
|
|
|
|
* @default null
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 14:18:42 +00:00
|
|
|
this.frame = null;
|
2017-10-17 03:16:08 +00:00
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#index
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.index = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The x coordinate of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#x
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 14:18:42 +00:00
|
|
|
this.x = 0;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The y coordinate of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#y
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 14:18:42 +00:00
|
|
|
this.y = 0;
|
2017-10-17 03:16:08 +00:00
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The x velocity of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#velocityX
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.velocityX = 0;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The y velocity of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#velocityY
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.velocityY = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The x acceleration of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#accelerationX
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 15:04:05 +00:00
|
|
|
this.accelerationX = 0;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The y acceleration of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#accelerationY
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 15:04:05 +00:00
|
|
|
this.accelerationY = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The maximum horizontal velocity this Particle can travel at.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#maxVelocityX
|
|
|
|
* @type {number}
|
|
|
|
* @default 10000
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 15:04:05 +00:00
|
|
|
this.maxVelocityX = 10000;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum vertical velocity this Particle can travel at.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#maxVelocityY
|
|
|
|
* @type {number}
|
|
|
|
* @default 10000
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 15:04:05 +00:00
|
|
|
this.maxVelocityY = 10000;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The bounciness, or restitution, of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#bounce
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 15:04:05 +00:00
|
|
|
this.bounce = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The horizontal scale of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#scaleX
|
|
|
|
* @type {float}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.scaleX = 1;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The vertical scale of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#scaleY
|
|
|
|
* @type {float}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.scaleY = 1;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The alpha value of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#alpha
|
|
|
|
* @type {float}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 01:26:15 +00:00
|
|
|
this.alpha = 1;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The angle of this Particle in degrees.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#angle
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-20 17:49:45 +00:00
|
|
|
this.angle = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The angle of this Particle in radians.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#rotation
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.rotation = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The horizontal scroll factor of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#scrollFactorX
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.scrollFactorX = 1;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The vertical scroll factor of this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#scrollFactorY
|
|
|
|
* @type {number}
|
|
|
|
* @default 1
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
this.scrollFactorY = 1;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The tint applied to this Particle.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#tint
|
|
|
|
* @type {number}
|
|
|
|
* @webglOnly
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-27 20:19:30 +00:00
|
|
|
this.tint = 0xffffffff;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [description]
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#color
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 01:26:15 +00:00
|
|
|
this.color = 0xffffffff;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The lifespan of this Particle in ms.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#life
|
|
|
|
* @type {number}
|
|
|
|
* @default 1000
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 01:26:15 +00:00
|
|
|
this.life = 1000;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The current life of this Particle in ms.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#lifeCurrent
|
|
|
|
* @type {number}
|
|
|
|
* @default 1000
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 01:26:15 +00:00
|
|
|
this.lifeCurrent = 1000;
|
2018-02-06 22:25:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The delay applied to this Particle upon emission, in ms.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#delayCurrent
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-27 11:31:37 +00:00
|
|
|
this.delayCurrent = 0;
|
2017-10-17 03:16:08 +00:00
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The normalized lifespan T value.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#lifeT
|
|
|
|
* @type {float}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-25 15:05:22 +00:00
|
|
|
this.lifeT = 0;
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* The data used by the ease equation.
|
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.Particle#data
|
|
|
|
* @type {object}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-18 01:26:15 +00:00
|
|
|
this.data = {
|
|
|
|
tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
|
2017-10-23 16:11:13 +00:00
|
|
|
alpha: { min: 1, max: 1 },
|
2017-10-24 02:31:54 +00:00
|
|
|
rotate: { min: 0, max: 0 },
|
2017-10-23 16:11:13 +00:00
|
|
|
scaleX: { min: 1, max: 1 },
|
|
|
|
scaleY: { min: 1, max: 1 }
|
2017-10-17 03:16:08 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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`.
|
|
|
|
*/
|
2017-10-17 03:16:08 +00:00
|
|
|
isAlive: function ()
|
|
|
|
{
|
2017-10-18 01:26:15 +00:00
|
|
|
return (this.lifeCurrent > 0);
|
2017-10-17 03:16:08 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-01-12 17:09:09 +00:00
|
|
|
fire: function (x, y)
|
2017-10-17 03:16:08 +00:00
|
|
|
{
|
2017-10-21 04:05:51 +00:00
|
|
|
var emitter = this.emitter;
|
|
|
|
|
2017-10-18 14:18:42 +00:00
|
|
|
this.frame = emitter.getFrame();
|
2017-10-18 01:26:15 +00:00
|
|
|
|
2017-10-29 21:46:41 +00:00
|
|
|
if (emitter.emitZone)
|
2017-10-18 14:18:42 +00:00
|
|
|
{
|
2017-10-24 02:02:03 +00:00
|
|
|
// Updates particle.x and particle.y during this call
|
2017-10-29 21:46:41 +00:00
|
|
|
emitter.emitZone.getPoint(this);
|
2017-10-18 14:18:42 +00:00
|
|
|
}
|
2017-10-18 01:26:15 +00:00
|
|
|
|
2017-10-24 02:02:03 +00:00
|
|
|
if (x === undefined)
|
|
|
|
{
|
|
|
|
if (emitter.follow)
|
|
|
|
{
|
|
|
|
this.x += emitter.follow.x + emitter.followOffset.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.x += emitter.x.onEmit(this, 'x');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.x += x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y === undefined)
|
|
|
|
{
|
|
|
|
if (emitter.follow)
|
|
|
|
{
|
|
|
|
this.y += emitter.follow.y + emitter.followOffset.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.y += emitter.y.onEmit(this, 'y');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.y += y;
|
|
|
|
}
|
2017-10-18 01:26:15 +00:00
|
|
|
|
2017-10-27 20:19:30 +00:00
|
|
|
this.life = emitter.lifespan.onEmit(this, 'lifespan');
|
|
|
|
this.lifeCurrent = this.life;
|
|
|
|
this.lifeT = 0;
|
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
var sx = emitter.speedX.onEmit(this, 'speedX');
|
|
|
|
var sy = (emitter.speedY) ? emitter.speedY.onEmit(this, 'speedY') : sx;
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-18 14:18:42 +00:00
|
|
|
if (emitter.radial)
|
2017-10-18 01:26:15 +00:00
|
|
|
{
|
2017-10-24 02:31:54 +00:00
|
|
|
var rad = DegToRad(emitter.angle.onEmit(this, 'angle'));
|
2017-10-18 14:18:42 +00:00
|
|
|
|
|
|
|
this.velocityX = Math.cos(rad) * Math.abs(sx);
|
|
|
|
this.velocityY = Math.sin(rad) * Math.abs(sy);
|
|
|
|
}
|
2017-10-27 20:19:30 +00:00
|
|
|
else if (emitter.moveTo)
|
|
|
|
{
|
|
|
|
var mx = emitter.moveToX.onEmit(this, 'moveToX');
|
|
|
|
var my = (emitter.moveToY) ? emitter.moveToY.onEmit(this, 'moveToY') : mx;
|
|
|
|
|
|
|
|
var angle = Math.atan2(my - this.y, mx - this.x);
|
|
|
|
|
|
|
|
var speed = DistanceBetween(this.x, this.y, mx, my) / (this.life / 1000);
|
|
|
|
|
|
|
|
// We know how many pixels we need to move, but how fast?
|
|
|
|
// var speed = this.distanceToXY(displayObject, x, y) / (maxTime / 1000);
|
|
|
|
|
|
|
|
this.velocityX = Math.cos(angle) * speed;
|
|
|
|
this.velocityY = Math.sin(angle) * speed;
|
|
|
|
}
|
2017-10-18 14:18:42 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
this.velocityX = sx;
|
|
|
|
this.velocityY = sy;
|
2017-10-18 01:26:15 +00:00
|
|
|
}
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-24 15:04:05 +00:00
|
|
|
if (emitter.acceleration)
|
|
|
|
{
|
|
|
|
this.accelerationX = emitter.accelerationX.onEmit(this, 'accelerationX');
|
|
|
|
this.accelerationY = emitter.accelerationY.onEmit(this, 'accelerationY');
|
|
|
|
}
|
|
|
|
|
|
|
|
this.maxVelocityX = emitter.maxVelocityX.onEmit(this, 'maxVelocityX');
|
|
|
|
this.maxVelocityY = emitter.maxVelocityY.onEmit(this, 'maxVelocityY');
|
|
|
|
|
2017-10-27 13:51:52 +00:00
|
|
|
this.delayCurrent = emitter.delay.onEmit(this, 'delay');
|
2017-10-27 11:31:37 +00:00
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
this.scaleX = emitter.scaleX.onEmit(this, 'scaleX');
|
|
|
|
this.scaleY = (emitter.scaleY) ? emitter.scaleY.onEmit(this, 'scaleY') : this.scaleX;
|
2017-10-20 17:49:45 +00:00
|
|
|
|
2017-10-24 02:31:54 +00:00
|
|
|
this.angle = emitter.rotate.onEmit(this, 'rotate');
|
2017-10-23 16:11:13 +00:00
|
|
|
this.rotation = DegToRad(this.angle);
|
2017-10-20 00:49:03 +00:00
|
|
|
|
2017-10-25 01:25:06 +00:00
|
|
|
this.bounce = emitter.bounce.onEmit(this, 'bounce');
|
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
this.alpha = emitter.alpha.onEmit(this, 'alpha');
|
2017-10-20 17:49:45 +00:00
|
|
|
|
2017-10-27 20:19:30 +00:00
|
|
|
this.tint = emitter.tint.onEmit(this, 'tint');
|
|
|
|
|
|
|
|
this.color = (this.tint & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
|
2017-10-17 20:32:45 +00:00
|
|
|
|
|
|
|
this.index = emitter.alive.length;
|
2017-10-17 03:16:08 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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 {float} step - The delta value divided by 1000.
|
|
|
|
* @param {array} processors - [description]
|
|
|
|
*/
|
2017-10-25 15:05:22 +00:00
|
|
|
computeVelocity: function (emitter, delta, step, processors)
|
2017-10-24 15:04:05 +00:00
|
|
|
{
|
|
|
|
var vx = this.velocityX;
|
|
|
|
var vy = this.velocityY;
|
|
|
|
|
|
|
|
var ax = this.accelerationX;
|
|
|
|
var ay = this.accelerationY;
|
|
|
|
|
|
|
|
var mx = this.maxVelocityX;
|
|
|
|
var my = 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;
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:25:06 +00:00
|
|
|
this.velocityX = vx;
|
|
|
|
this.velocityY = vy;
|
2017-10-25 15:05:22 +00:00
|
|
|
|
|
|
|
// Apply any additional processors
|
|
|
|
for (var i = 0; i < processors.length; i++)
|
|
|
|
{
|
|
|
|
processors[i].update(this, delta, step);
|
|
|
|
}
|
2017-10-25 01:25:06 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-10-25 01:25:06 +00:00
|
|
|
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;
|
|
|
|
}
|
2017-10-24 15:04:05 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:25:23 +00:00
|
|
|
/**
|
|
|
|
* 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 {float} step - The delta value divided by 1000.
|
|
|
|
* @param {array} processors - An optional array of update processors.
|
|
|
|
*
|
|
|
|
* @return {boolean} Returns `true` if this Particle has now expired and should be removed, otherwise `false` if still active.
|
|
|
|
*/
|
2017-10-25 15:05:22 +00:00
|
|
|
update: function (delta, step, processors)
|
2017-10-17 03:16:08 +00:00
|
|
|
{
|
2017-10-27 11:31:37 +00:00
|
|
|
if (this.delayCurrent > 0)
|
|
|
|
{
|
|
|
|
this.delayCurrent -= delta;
|
2017-10-27 13:51:52 +00:00
|
|
|
|
2017-10-27 11:31:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-21 04:05:51 +00:00
|
|
|
var emitter = this.emitter;
|
|
|
|
|
2017-10-18 01:26:15 +00:00
|
|
|
// How far along in life is this particle? (t = 0 to 1)
|
2017-10-20 00:49:03 +00:00
|
|
|
var t = 1 - (this.lifeCurrent / this.life);
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-25 15:05:22 +00:00
|
|
|
this.lifeT = t;
|
|
|
|
|
|
|
|
this.computeVelocity(emitter, delta, step, processors);
|
2017-10-24 15:04:05 +00:00
|
|
|
|
2017-10-25 01:25:06 +00:00
|
|
|
this.x += this.velocityX * step;
|
|
|
|
this.y += this.velocityY * step;
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-25 01:25:06 +00:00
|
|
|
if (emitter.bounds)
|
|
|
|
{
|
|
|
|
this.checkBounds(emitter);
|
|
|
|
}
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-29 21:46:41 +00:00
|
|
|
if (emitter.deathZone && emitter.deathZone.willKill(this))
|
|
|
|
{
|
|
|
|
this.lifeCurrent = 0;
|
|
|
|
|
|
|
|
// No need to go any further, particle has been killed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
this.scaleX = emitter.scaleX.onUpdate(this, 'scaleX', t, this.scaleX);
|
2017-10-20 17:49:45 +00:00
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
if (emitter.scaleY)
|
|
|
|
{
|
|
|
|
this.scaleY = emitter.scaleY.onUpdate(this, 'scaleY', t, this.scaleY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.scaleY = this.scaleX;
|
|
|
|
}
|
2017-10-20 00:49:03 +00:00
|
|
|
|
2017-10-24 02:31:54 +00:00
|
|
|
this.angle = emitter.rotate.onUpdate(this, 'rotate', t, this.angle);
|
2017-10-20 17:49:45 +00:00
|
|
|
this.rotation = DegToRad(this.angle);
|
2017-10-18 01:26:15 +00:00
|
|
|
|
2017-10-23 16:11:13 +00:00
|
|
|
this.alpha = emitter.alpha.onUpdate(this, 'alpha', t, this.alpha);
|
2017-10-18 01:26:15 +00:00
|
|
|
|
2017-10-27 20:19:30 +00:00
|
|
|
this.tint = emitter.tint.onUpdate(this, 'tint', t, this.tint);
|
|
|
|
|
|
|
|
this.color = (this.tint & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
|
2017-10-18 01:26:15 +00:00
|
|
|
|
|
|
|
this.lifeCurrent -= delta;
|
2017-10-17 20:32:45 +00:00
|
|
|
|
2017-10-18 01:26:15 +00:00
|
|
|
return (this.lifeCurrent <= 0);
|
2017-10-17 03:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Particle;
|