2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2018-02-12 16:01:20 +00:00
|
|
|
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
|
|
|
*/
|
|
|
|
|
2017-10-24 02:02:03 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
var FloatBetween = require('../../math/FloatBetween');
|
2018-02-10 14:56:08 +00:00
|
|
|
var GetEaseFunction = require('../../tweens/builders/GetEaseFunction');
|
2017-10-24 02:02:03 +00:00
|
|
|
var GetFastValue = require('../../utils/object/GetFastValue');
|
|
|
|
var Wrap = require('../../math/Wrap');
|
|
|
|
|
2018-03-19 21:27:16 +00:00
|
|
|
/**
|
2018-04-18 15:32:03 +00:00
|
|
|
* The returned value sets what the property will be at the START of the particle's life, on emit.
|
2018-03-19 21:27:16 +00:00
|
|
|
* @callback EmitterOpOnEmitCallback
|
|
|
|
*
|
2018-04-18 15:32:03 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
|
|
|
* @param {number} value - The current value of the property.
|
2018-03-19 21:27:16 +00:00
|
|
|
*
|
2018-04-18 15:32:03 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-03-19 21:27:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-04-18 15:32:03 +00:00
|
|
|
* The returned value updates the property for the duration of the particle's life.
|
2018-03-19 21:27:16 +00:00
|
|
|
* @callback EmitterOpOnUpdateCallback
|
|
|
|
*
|
2018-04-18 15:32:03 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {number} t - The normalized lifetime of the particle, between 0 (start) and 1 (end).
|
2018-04-18 15:32:03 +00:00
|
|
|
* @param {number} value - The current value of the property.
|
|
|
|
*
|
|
|
|
* @return {number} The new value of the property.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an operation yielding a random value within a range.
|
|
|
|
* @typedef {object} EmitterOpRandomConfig
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @property {number[]} random - The minimum and maximum values, as [min, max].
|
2018-04-18 15:32:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an operation yielding a random value within a range.
|
|
|
|
* @typedef {object} EmitterOpRandomMinMaxConfig
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @property {number} min - The minimum value.
|
|
|
|
* @property {number} max - The maximum value.
|
2018-04-18 15:32:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an operation yielding a random value within a range.
|
|
|
|
* @typedef {object} EmitterOpRandomStartEndConfig
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @property {number} start - The starting value.
|
|
|
|
* @property {number} end - The ending value.
|
2018-04-18 15:32:03 +00:00
|
|
|
* @property {boolean} random - If false, this becomes {@link EmitterOpEaseConfig}.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an operation yielding a value incremented continuously across a range.
|
|
|
|
* @typedef {object} EmitterOpEaseConfig
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @property {number} start - The starting value.
|
|
|
|
* @property {number} end - The ending value.
|
2018-04-18 15:32:03 +00:00
|
|
|
* @property {string} [ease='Linear'] - The name of the easing function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines an operation yielding a value incremented by steps across a range.
|
|
|
|
* @typedef {object} EmitterOpSteppedConfig
|
2018-03-19 21:27:16 +00:00
|
|
|
*
|
2018-04-18 15:32:03 +00:00
|
|
|
* @property {number} start - The starting value.
|
|
|
|
* @property {number} end - The ending value.
|
|
|
|
* @property {number} steps - The number of steps between start and end.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} EmitterOpCustomEmitConfig
|
|
|
|
*
|
2018-10-19 17:29:36 +00:00
|
|
|
* @property {EmitterOpOnEmitCallback} onEmit - A callback that is invoked each time the emitter emits a particle.
|
2018-04-18 15:32:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {object} EmitterOpCustomUpdateConfig
|
|
|
|
*
|
2018-10-19 17:29:36 +00:00
|
|
|
* @property {EmitterOpOnEmitCallback} [onEmit] - A callback that is invoked each time the emitter emits a particle.
|
|
|
|
* @property {EmitterOpOnUpdateCallback} onUpdate - A callback that is invoked each time the emitter updates.
|
2018-03-19 21:27:16 +00:00
|
|
|
*/
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-02-07 15:27:21 +00:00
|
|
|
* @classdesc
|
2018-06-20 15:17:45 +00:00
|
|
|
* A Particle Emitter property.
|
|
|
|
*
|
|
|
|
* Facilitates changing Particle properties as they are emitted and throughout their lifetime.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @class EmitterOp
|
2018-10-10 09:49:13 +00:00
|
|
|
* @memberof Phaser.GameObjects.Particles
|
2018-02-06 22:37:56 +00:00
|
|
|
* @constructor
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {ParticleEmitterConfig} config - Settings for the Particle Emitter that owns this property.
|
2018-06-21 13:18:28 +00:00
|
|
|
* @param {string} key - The name of the property.
|
|
|
|
* @param {number} defaultValue - The default value of the property.
|
|
|
|
* @param {boolean} [emitOnly=false] - Whether the property can only be modified when a Particle is emitted.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
var EmitterOp = new Class({
|
2018-04-22 23:13:11 +00:00
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function EmitterOp (config, key, defaultValue, emitOnly)
|
2017-10-24 02:02:03 +00:00
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
if (emitOnly === undefined)
|
|
|
|
{
|
|
|
|
emitOnly = false;
|
|
|
|
}
|
2017-10-24 15:04:05 +00:00
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* The name of this property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#propertyKey
|
|
|
|
* @type {string}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.propertyKey = key;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The value of this property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#propertyValue
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-30 02:22:21 +00:00
|
|
|
this.propertyValue = defaultValue;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The default value of this property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#defaultValue
|
|
|
|
* @type {number}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.defaultValue = defaultValue;
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The number of steps for stepped easing between {@link Phaser.GameObjects.Particles.EmitterOp#start} and
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#end} values, per emit.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#steps
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.steps = 0;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The step counter for stepped easing, per emit.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#counter
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.counter = 0;
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The start value for this property to ease between.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#start
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.start = 0;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The end value for this property to ease between.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#end
|
|
|
|
* @type {number}
|
|
|
|
* @default 0
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.end = 0;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* The easing function to use for updating this property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#ease
|
|
|
|
* @type {?function}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.ease;
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* Whether this property can only be modified when a Particle is emitted.
|
|
|
|
*
|
|
|
|
* Set to `true` to allow only {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} callbacks to be set and
|
|
|
|
* affect this property.
|
|
|
|
*
|
|
|
|
* Set to `false` to allow both {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks to be set and affect this property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#emitOnly
|
|
|
|
* @type {boolean}
|
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-30 02:22:21 +00:00
|
|
|
this.emitOnly = emitOnly;
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The callback to run for Particles when they are emitted from the Particle Emitter.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#onEmit
|
2018-03-19 21:27:16 +00:00
|
|
|
* @type {EmitterOpOnEmitCallback}
|
2018-02-06 22:37:56 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.onEmit = this.defaultEmit;
|
2018-02-06 22:37:56 +00:00
|
|
|
|
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* The callback to run for Particles when they are updated.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @name Phaser.GameObjects.Particles.EmitterOp#onUpdate
|
2018-03-19 21:27:16 +00:00
|
|
|
* @type {EmitterOpOnUpdateCallback}
|
2018-02-06 22:37:56 +00:00
|
|
|
* @since 3.0.0
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
this.onUpdate = this.defaultUpdate;
|
|
|
|
|
2017-10-30 02:22:21 +00:00
|
|
|
this.loadConfig(config);
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 15:17:45 +00:00
|
|
|
* Load the property from a Particle Emitter configuration object.
|
|
|
|
*
|
|
|
|
* Optionally accepts a new property key to use, replacing the current one.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#loadConfig
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {ParticleEmitterConfig} [config] - Settings for the Particle Emitter that owns this property.
|
|
|
|
* @param {string} [newKey] - The new key to use for this property, if any.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-30 02:22:21 +00:00
|
|
|
loadConfig: function (config, newKey)
|
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
if (config === undefined)
|
|
|
|
{
|
|
|
|
config = {};
|
|
|
|
}
|
2017-10-30 02:22:21 +00:00
|
|
|
|
|
|
|
if (newKey)
|
|
|
|
{
|
|
|
|
this.propertyKey = newKey;
|
|
|
|
}
|
|
|
|
|
2018-03-27 12:52:58 +00:00
|
|
|
this.propertyValue = GetFastValue(
|
|
|
|
config,
|
|
|
|
this.propertyKey,
|
|
|
|
this.defaultValue
|
|
|
|
);
|
2017-10-30 02:22:21 +00:00
|
|
|
|
2017-10-24 02:02:03 +00:00
|
|
|
this.setMethods();
|
2017-10-24 15:04:05 +00:00
|
|
|
|
2017-10-30 02:22:21 +00:00
|
|
|
if (this.emitOnly)
|
2017-10-24 15:04:05 +00:00
|
|
|
{
|
|
|
|
// Reset it back again
|
|
|
|
this.onUpdate = this.defaultUpdate;
|
|
|
|
}
|
2017-10-24 02:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 15:17:45 +00:00
|
|
|
* Build a JSON representation of this Particle Emitter property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#toJSON
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @return {object} A JSON representation of this Particle Emitter property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-30 02:22:21 +00:00
|
|
|
toJSON: function ()
|
|
|
|
{
|
2018-04-24 02:23:42 +00:00
|
|
|
return this.propertyValue;
|
2017-10-30 02:22:21 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* Change the current value of the property and update its callback methods.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#onChange
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {number} value - The value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Particles.EmitterOp} This Emitter Op object.
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
onChange: function (value)
|
|
|
|
{
|
|
|
|
this.propertyValue = value;
|
|
|
|
|
|
|
|
return this.setMethods();
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 16:18:03 +00:00
|
|
|
* Update the {@link Phaser.GameObjects.Particles.EmitterOp#onEmit} and
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#onUpdate} callbacks based on the type of the current
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#propertyValue}.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#setMethods
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @return {Phaser.GameObjects.Particles.EmitterOp} This Emitter Op object.
|
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
setMethods: function ()
|
|
|
|
{
|
|
|
|
var value = this.propertyValue;
|
|
|
|
|
2018-03-27 12:52:58 +00:00
|
|
|
var t = typeof value;
|
2017-10-24 02:02:03 +00:00
|
|
|
|
|
|
|
if (t === 'number')
|
|
|
|
{
|
|
|
|
// Explicit static value:
|
|
|
|
// x: 400
|
|
|
|
|
|
|
|
this.onEmit = this.staticValueEmit;
|
2018-04-18 15:32:03 +00:00
|
|
|
this.onUpdate = this.staticValueUpdate; // How?
|
2017-10-24 02:02:03 +00:00
|
|
|
}
|
|
|
|
else if (Array.isArray(value))
|
|
|
|
{
|
|
|
|
// Picks a random element from the array:
|
|
|
|
// x: [ 100, 200, 300, 400 ]
|
|
|
|
|
|
|
|
this.onEmit = this.randomStaticValueEmit;
|
|
|
|
}
|
|
|
|
else if (t === 'function')
|
|
|
|
{
|
2017-10-30 17:04:03 +00:00
|
|
|
// The same as setting just the onUpdate function and no onEmit (unless this op is an emitOnly one)
|
2017-10-24 02:02:03 +00:00
|
|
|
// Custom callback, must return a value:
|
|
|
|
|
|
|
|
/*
|
|
|
|
x: function (particle, key, t, value)
|
|
|
|
{
|
|
|
|
return value + 50;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-10-30 17:04:03 +00:00
|
|
|
if (this.emitOnly)
|
|
|
|
{
|
|
|
|
this.onEmit = value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.onUpdate = value;
|
|
|
|
}
|
2017-10-24 02:02:03 +00:00
|
|
|
}
|
2018-04-22 23:13:11 +00:00
|
|
|
else if (t === 'object' && (this.has(value, 'random') || this.hasBoth(value, 'start', 'end') || this.hasBoth(value, 'min', 'max')))
|
2017-10-24 02:02:03 +00:00
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
this.start = this.has(value, 'start') ? value.start : value.min;
|
|
|
|
this.end = this.has(value, 'end') ? value.end : value.max;
|
2017-10-24 02:02:03 +00:00
|
|
|
|
2018-04-22 23:13:11 +00:00
|
|
|
var isRandom = (this.hasBoth(value, 'min', 'max') || this.has(value, 'random'));
|
2017-10-24 02:02:03 +00:00
|
|
|
|
|
|
|
// A random starting value (using 'min | max' instead of 'start | end' automatically implies a random value)
|
|
|
|
|
|
|
|
// x: { start: 100, end: 400, random: true } OR { min: 100, max: 400 } OR { random: [ 100, 400 ] }
|
|
|
|
|
|
|
|
if (isRandom)
|
|
|
|
{
|
|
|
|
var rnd = value.random;
|
|
|
|
|
|
|
|
// x: { random: [ 100, 400 ] } = the same as doing: x: { start: 100, end: 400, random: true }
|
|
|
|
if (Array.isArray(rnd))
|
|
|
|
{
|
|
|
|
this.start = rnd[0];
|
|
|
|
this.end = rnd[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.onEmit = this.randomRangedValueEmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.has(value, 'steps'))
|
|
|
|
{
|
|
|
|
// A stepped (per emit) range
|
|
|
|
|
|
|
|
// x: { start: 100, end: 400, steps: 64 }
|
|
|
|
|
|
|
|
// Increments a value stored in the emitter
|
|
|
|
|
|
|
|
this.steps = value.steps;
|
|
|
|
this.counter = this.start;
|
|
|
|
|
|
|
|
this.onEmit = this.steppedEmit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// An eased range (defaults to Linear if not specified)
|
|
|
|
|
|
|
|
// x: { start: 100, end: 400, [ ease: 'Linear' ] }
|
|
|
|
|
2018-03-27 12:52:58 +00:00
|
|
|
var easeType = this.has(value, 'ease') ? value.ease : 'Linear';
|
2017-10-24 02:02:03 +00:00
|
|
|
|
|
|
|
this.ease = GetEaseFunction(easeType);
|
|
|
|
|
|
|
|
if (!isRandom)
|
|
|
|
{
|
|
|
|
this.onEmit = this.easedValueEmit;
|
|
|
|
}
|
|
|
|
|
2018-04-18 15:32:03 +00:00
|
|
|
// BUG: alpha, rotate, scaleX, scaleY, or tint are eased here if {min, max} is given.
|
|
|
|
// Probably this branch should exclude isRandom entirely.
|
|
|
|
|
2017-10-24 02:02:03 +00:00
|
|
|
this.onUpdate = this.easeValueUpdate;
|
|
|
|
}
|
|
|
|
}
|
2018-04-22 23:13:11 +00:00
|
|
|
else if (t === 'object' && this.hasEither(value, 'onEmit', 'onUpdate'))
|
2017-10-24 02:02:03 +00:00
|
|
|
{
|
|
|
|
// Custom onEmit and onUpdate callbacks
|
|
|
|
|
|
|
|
/*
|
|
|
|
x: {
|
|
|
|
// Called at the start of the particles life, when it is being created
|
|
|
|
onEmit: function (particle, key, t, value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Called during the particles life on each update
|
|
|
|
onUpdate: function (particle, key, t, value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (this.has(value, 'onEmit'))
|
|
|
|
{
|
|
|
|
this.onEmit = value.onEmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.has(value, 'onUpdate'))
|
|
|
|
{
|
|
|
|
this.onUpdate = value.onUpdate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 15:17:45 +00:00
|
|
|
* Check whether an object has the given property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#has
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {object} object - The object to check.
|
|
|
|
* @param {string} key - The key of the property to look for in the object.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @return {boolean} `true` if the property exists in the object, `false` otherwise.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
has: function (object, key)
|
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
return object.hasOwnProperty(key);
|
2017-10-24 02:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 15:17:45 +00:00
|
|
|
* Check whether an object has both of the given properties.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#hasBoth
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {object} object - The object to check.
|
|
|
|
* @param {string} key1 - The key of the first property to check the object for.
|
|
|
|
* @param {string} key2 - The key of the second property to check the object for.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @return {boolean} `true` if both properties exist in the object, `false` otherwise.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
hasBoth: function (object, key1, key2)
|
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
return object.hasOwnProperty(key1) && object.hasOwnProperty(key2);
|
2017-10-24 02:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-20 15:17:45 +00:00
|
|
|
* Check whether an object has at least one of the given properties.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#hasEither
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {object} object - The object to check.
|
|
|
|
* @param {string} key1 - The key of the first property to check the object for.
|
|
|
|
* @param {string} key2 - The key of the second property to check the object for.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-20 15:17:45 +00:00
|
|
|
* @return {boolean} `true` if at least one of the properties exists in the object, `false` if neither exist.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
hasEither: function (object, key1, key2)
|
|
|
|
{
|
2018-03-27 12:52:58 +00:00
|
|
|
return object.hasOwnProperty(key1) || object.hasOwnProperty(key2);
|
2017-10-24 02:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
|
|
|
* The returned value sets what the property will be at the START of the particles life, on emit.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#defaultEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
|
|
|
* @param {number} [value] - The current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of hte property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
defaultEmit: function (particle, key, value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
|
|
|
* The returned value updates the property for the duration of the particles life.
|
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#defaultUpdate
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
2018-06-20 15:17:45 +00:00
|
|
|
* @param {number} t - The T value (between 0 and 1)
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {number} value - The current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
defaultUpdate: function (particle, key, t, value)
|
|
|
|
{
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onEmit` callback that returns the current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#staticValueEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
staticValueEmit: function ()
|
|
|
|
{
|
|
|
|
return this.propertyValue;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onUpdate` callback that returns the current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#staticValueUpdate
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The current value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
staticValueUpdate: function ()
|
|
|
|
{
|
|
|
|
return this.propertyValue;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onEmit` callback that returns a random value from the current value array.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#randomStaticValueEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
randomStaticValueEmit: function ()
|
|
|
|
{
|
|
|
|
var randomIndex = Math.floor(Math.random() * this.propertyValue.length);
|
|
|
|
|
|
|
|
return this.propertyValue[randomIndex];
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onEmit` callback that returns a value between the {@link Phaser.GameObjects.Particles.EmitterOp#start} and
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#end} range.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#randomRangedValueEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The key of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
randomRangedValueEmit: function (particle, key)
|
|
|
|
{
|
|
|
|
var value = FloatBetween(this.start, this.end);
|
|
|
|
|
2017-10-24 02:31:54 +00:00
|
|
|
if (particle && particle.data[key])
|
2017-10-24 02:02:03 +00:00
|
|
|
{
|
2017-10-24 02:31:54 +00:00
|
|
|
particle.data[key].min = value;
|
2017-10-24 02:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onEmit` callback that returns a stepped value between the
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end}
|
|
|
|
* range.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#steppedEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
steppedEmit: function ()
|
|
|
|
{
|
2017-10-27 20:19:30 +00:00
|
|
|
var current = this.counter;
|
|
|
|
|
2018-03-27 12:52:58 +00:00
|
|
|
var next = this.counter + (this.end - this.start) / this.steps;
|
2017-10-24 02:02:03 +00:00
|
|
|
|
|
|
|
this.counter = Wrap(next, this.start, this.end);
|
|
|
|
|
2017-10-27 20:19:30 +00:00
|
|
|
return current;
|
2017-10-24 02:02:03 +00:00
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onEmit` callback that returns an eased value between the
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end}
|
|
|
|
* range.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#easedValueEmit
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2017-10-24 02:02:03 +00:00
|
|
|
easedValueEmit: function (particle, key)
|
|
|
|
{
|
2017-10-24 15:04:05 +00:00
|
|
|
if (particle && particle.data[key])
|
2017-10-24 02:31:54 +00:00
|
|
|
{
|
|
|
|
var data = particle.data[key];
|
2017-10-24 02:02:03 +00:00
|
|
|
|
2017-10-24 02:31:54 +00:00
|
|
|
data.min = this.start;
|
|
|
|
data.max = this.end;
|
|
|
|
}
|
2017-10-24 02:02:03 +00:00
|
|
|
|
|
|
|
return this.start;
|
|
|
|
},
|
|
|
|
|
2018-02-06 22:37:56 +00:00
|
|
|
/**
|
2018-06-21 11:47:19 +00:00
|
|
|
* An `onUpdate` callback that returns an eased value between the
|
|
|
|
* {@link Phaser.GameObjects.Particles.EmitterOp#start} and {@link Phaser.GameObjects.Particles.EmitterOp#end}
|
|
|
|
* range.
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
|
|
|
* @method Phaser.GameObjects.Particles.EmitterOp#easeValueUpdate
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
|
|
|
|
* @param {string} key - The name of the property.
|
|
|
|
* @param {number} t - The T value (between 0 and 1)
|
2018-02-06 22:37:56 +00:00
|
|
|
*
|
2018-06-21 11:47:19 +00:00
|
|
|
* @return {number} The new value of the property.
|
2018-02-06 22:37:56 +00:00
|
|
|
*/
|
2018-02-16 19:17:49 +00:00
|
|
|
easeValueUpdate: function (particle, key, t)
|
2017-10-24 02:02:03 +00:00
|
|
|
{
|
|
|
|
var data = particle.data[key];
|
|
|
|
|
|
|
|
return (data.max - data.min) * this.ease(t) + data.min;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = EmitterOp;
|