Skip to content

Commit f85ae5d

Browse files
committed
Finished the new Zones.
1 parent 9cee892 commit f85ae5d

2 files changed

Lines changed: 42 additions & 14 deletions

File tree

v3/src/gameobjects/particles/ParticleEmitter.js

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
var BlendModes = require('../../renderer/BlendModes');
22
var Class = require('../../utils/Class');
33
var Components = require('../components');
4+
var EdgeZone = require('./zones/EdgeZone');
45
var EmitterOp = require('./EmitterOp');
56
var GetFastValue = require('../../utils/object/GetFastValue');
67
var GetRandomElement = require('../../utils/array/GetRandomElement');
78
var GetValue = require('../../utils/object/GetValue');
89
var Particle = require('./Particle');
10+
var RandomZone = require('./zones/RandomZone');
911
var Rectangle = require('../../geom/rectangle/Rectangle');
1012
var StableSort = require('../../utils/array/StableSort');
1113
var Vector2 = require('../../math/Vector2');
@@ -135,7 +137,12 @@ var ParticleEmitter = new Class({
135137

136138
this._counter = 0;
137139

138-
this.zone = GetFastValue(config, 'zone', null);
140+
this.zone = null;
141+
142+
if (config.hasOwnProperty('zone'))
143+
{
144+
this.setZone(config.zone);
145+
}
139146

140147
// bounds rectangle
141148
this.bounds = null;
@@ -150,9 +157,6 @@ var ParticleEmitter = new Class({
150157
this.collideTop = GetFastValue(config, 'collideTop', true);
151158
this.collideBottom = GetFastValue(config, 'collideBottom', true);
152159

153-
// Optional Particle emission zone - must be an object that supports a `getRandomPoint` function, such as a Rectangle, Circle, Path, etc.
154-
this.zone = GetFastValue(config, 'zone', null);
155-
156160
this.active = GetFastValue(config, 'active', true);
157161
this.visible = GetFastValue(config, 'visible', true);
158162

@@ -389,17 +393,37 @@ var ParticleEmitter = new Class({
389393
return this;
390394
},
391395

392-
// The zone must have a function called `getRandomPoint` that takes an object and sets
396+
// The zone must have a function called `getPoint` that takes an object and sets
393397
// its x and y properties accordingly then returns that object
394398
setZone: function (zone)
395399
{
396400
if (zone === undefined)
397401
{
398402
this.zone = null;
399403
}
400-
else if (typeof zone.getRandomPoint === 'function')
404+
else
401405
{
402-
this.zone = zone;
406+
// Where source = Geom like Circle, or a Path or Curve
407+
// zone: { source: X, random: true }
408+
// zone: { source: X, edge: true, quantity: 32 }
409+
410+
var source = GetFastValue(zone, 'source', null);
411+
412+
if (source && typeof source.getPoint === 'function')
413+
{
414+
// Valid source, is it random or edge?
415+
if (GetFastValue(zone, 'random', null))
416+
{
417+
this.zone = new RandomZone(source);
418+
}
419+
else
420+
{
421+
var quantity = GetFastValue(zone, 'quantity', 1);
422+
var stepRate = GetFastValue(zone, 'stepRate', 1);
423+
424+
this.zone = new EdgeZone(source, quantity, stepRate);
425+
}
426+
}
403427
}
404428

405429
return this;
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
var Class = require('../../../utils/Class');
2-
var GetFastValue = require('../../../utils/object/GetFastValue');
2+
var Wrap = require('../../../math/Wrap');
33

4-
var RandomZone = new Class({
4+
var EdgeZone = new Class({
55

66
initialize:
77

8-
function RandomZone (source, steps)
8+
function EdgeZone (source, quantity, stepRate)
99
{
10-
if (steps === undefined) { steps = 1; }
11-
1210
this.source = source;
1311

14-
this.steps = steps;
12+
this.points = source.getPoints(quantity, stepRate);
1513

1614
this.counter = 0;
1715
},
1816

1917
getPoint: function (particle)
2018
{
19+
var point = this.points[this.counter];
20+
21+
particle.x = point.x;
22+
particle.y = point.y;
23+
24+
this.counter = Wrap(this.counter + 1, 0, this.points.length - 1);
2125
}
2226

2327
});
2428

25-
module.exports = RandomZone;
29+
module.exports = EdgeZone;

0 commit comments

Comments
 (0)