Skip to content

Commit 0b881e9

Browse files
committed
Add particles docs
1 parent 75b250b commit 0b881e9

7 files changed

Lines changed: 554 additions & 276 deletions

File tree

src/gameobjects/particles/EmitterOp.js

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,95 @@ var GetFastValue = require('../../utils/object/GetFastValue');
1111
var Wrap = require('../../math/Wrap');
1212

1313
/**
14-
* The returned value sets what the property will be at the START of the particles life, on emit.
14+
* The returned value sets what the property will be at the START of the particle's life, on emit.
1515
* @callback EmitterOpOnEmitCallback
1616
*
17-
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
18-
* @param {string} key - [description]
19-
* @param {number} value - [description]
17+
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
18+
* @param {string} key - The name of the property.
19+
* @param {number} value - The current value of the property.
2020
*
21-
* @return {number} [description]
21+
* @return {number} The new value of the property.
2222
*/
2323

2424
/**
25-
* The returned value updates the property for the duration of the particles life.
25+
* The returned value updates the property for the duration of the particle's life.
2626
* @callback EmitterOpOnUpdateCallback
2727
*
28-
* @param {Phaser.GameObjects.Particles.Particle} particle - [description]
29-
* @param {string} key - [description]
30-
* @param {float} t - The T value (between 0 and 1)
31-
* @param {number} value - [description]
28+
* @param {Phaser.GameObjects.Particles.Particle} particle - The particle.
29+
* @param {string} key - The name of the property.
30+
* @param {float} t - The normalized lifetime of the particle, between 0 (start) and 1 (end).
31+
* @param {number} value - The current value of the property.
32+
*
33+
* @return {number} The new value of the property.
34+
*/
35+
36+
/**
37+
* Defines a value or an operation yielding a value, setting what a particle property will be at the START of the particle's life, on emit.
38+
* @typedef {float|float[]|EmitterOpOnEmitCallback|EmitterOpRandomConfig|EmitterOpRandomMinMaxConfig|EmitterOpRandomStartEndConfig|EmitterOpSteppedConfig|EmitterOpCustomEmitConfig} EmitterOpEmitConfig
39+
*
40+
* @see Phaser.GameObjects.Particles.Particle#fire
41+
*/
42+
43+
/**
44+
* Defines an operation yielding a value, updating a particle property for the duration of the particle's life.
45+
* @typedef {EmitterOpOnUpdateCallback|EmitterOpEaseConfig|EmitterOpCustomUpdateConfig} EmitterOpUpdateConfig
46+
*
47+
* @see Phaser.GameObjects.Particles.Particle#update
48+
*/
49+
50+
/**
51+
* Defines an operation yielding a random value within a range.
52+
* @typedef {object} EmitterOpRandomConfig
53+
*
54+
* @property {float[]} random - The minimum and maximum values, as [min, max].
55+
*/
56+
57+
/**
58+
* Defines an operation yielding a random value within a range.
59+
* @typedef {object} EmitterOpRandomMinMaxConfig
60+
*
61+
* @property {float} min - The minimum value.
62+
* @property {float} max - The maximum value.
63+
*/
64+
65+
/**
66+
* Defines an operation yielding a random value within a range.
67+
* @typedef {object} EmitterOpRandomStartEndConfig
68+
*
69+
* @property {float} start - The starting value.
70+
* @property {float} end - The ending value.
71+
* @property {boolean} random - If false, this becomes {@link EmitterOpEaseConfig}.
72+
*/
73+
74+
/**
75+
* Defines an operation yielding a value incremented continuously across a range.
76+
* @typedef {object} EmitterOpEaseConfig
77+
*
78+
* @property {float} start - The starting value.
79+
* @property {float} end - The ending value.
80+
* @property {string} [ease='Linear'] - The name of the easing function.
81+
*/
82+
83+
/**
84+
* Defines an operation yielding a value incremented by steps across a range.
85+
* @typedef {object} EmitterOpSteppedConfig
3286
*
33-
* @return {number} [description]
87+
* @property {number} start - The starting value.
88+
* @property {number} end - The ending value.
89+
* @property {number} steps - The number of steps between start and end.
90+
*/
91+
92+
/**
93+
* @typedef {object} EmitterOpCustomEmitConfig
94+
*
95+
* @property {EmitterOpOnEmitCallback} onEmit - [description]
96+
*/
97+
98+
/**
99+
* @typedef {object} EmitterOpCustomUpdateConfig
100+
*
101+
* @property {EmitterOpOnEmitCallback} [onEmit] - [description]
102+
* @property {EmitterOpOnUpdateCallback} onUpdate - [description]
34103
*/
35104

36105
/**
@@ -247,7 +316,7 @@ var EmitterOp = new Class({
247316
// x: 400
248317

249318
this.onEmit = this.staticValueEmit;
250-
this.onUpdate = this.staticValueUpdate;
319+
this.onUpdate = this.staticValueUpdate; // How?
251320
}
252321
else if (Array.isArray(value))
253322
{
@@ -327,6 +396,7 @@ var EmitterOp = new Class({
327396

328397
// x: { start: 100, end: 400, [ ease: 'Linear' ] }
329398

399+
330400
var easeType = this.has(value, 'ease') ? value.ease : 'Linear';
331401

332402
this.ease = GetEaseFunction(easeType);
@@ -336,6 +406,9 @@ var EmitterOp = new Class({
336406
this.onEmit = this.easedValueEmit;
337407
}
338408

409+
// BUG: alpha, rotate, scaleX, scaleY, or tint are eased here if {min, max} is given.
410+
// Probably this branch should exclude isRandom entirely.
411+
339412
this.onUpdate = this.easeValueUpdate;
340413
}
341414
}

src/gameobjects/particles/Particle.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var DistanceBetween = require('../../math/distance/DistanceBetween');
1010

1111
/**
1212
* @classdesc
13-
* [description]
13+
* A Particle is a simple Game Object controlled by a Particle Emitter and Manager, and rendered by the Manager.
14+
* It uses its own lightweight physics system, and can interact only with its Emitter's bounds and zones.
1415
*
1516
* @class Particle
1617
* @memberOf Phaser.GameObjects.Particles
@@ -37,7 +38,7 @@ var Particle = new Class({
3738
this.emitter = emitter;
3839

3940
/**
40-
* [description]
41+
* The texture frame used to render this Particle.
4142
*
4243
* @name Phaser.GameObjects.Particles.Particle#frame
4344
* @type {Phaser.Textures.Frame}
@@ -47,7 +48,7 @@ var Particle = new Class({
4748
this.frame = null;
4849

4950
/**
50-
* [description]
51+
* The position of this Particle within its Emitter's particle pool.
5152
*
5253
* @name Phaser.GameObjects.Particles.Particle#index
5354
* @type {number}
@@ -207,7 +208,7 @@ var Particle = new Class({
207208
this.tint = 0xffffffff;
208209

209210
/**
210-
* [description]
211+
* The full color of this Particle, computed from its alpha and tint.
211212
*
212213
* @name Phaser.GameObjects.Particles.Particle#color
213214
* @type {number}
@@ -246,7 +247,7 @@ var Particle = new Class({
246247
this.delayCurrent = 0;
247248

248249
/**
249-
* The normalized lifespan T value.
250+
* The normalized lifespan T value, where 0 is the start and 1 is the end.
250251
*
251252
* @name Phaser.GameObjects.Particles.Particle#lifeT
252253
* @type {float}
@@ -405,7 +406,7 @@ var Particle = new Class({
405406
* @param {Phaser.GameObjects.Particles.ParticleEmitter} emitter - The Emitter that is updating this Particle.
406407
* @param {number} delta - The delta time in ms.
407408
* @param {float} step - The delta value divided by 1000.
408-
* @param {array} processors - [description]
409+
* @param {array} processors - Particle processors (gravity wells).
409410
*/
410411
computeVelocity: function (emitter, delta, step, processors)
411412
{

0 commit comments

Comments
 (0)