Skip to content

Commit b1c9677

Browse files
committed
Fixed EdgeZone gaps and added yoyo support. Updated emitter config.
1 parent f85ae5d commit b1c9677

2 files changed

Lines changed: 60 additions & 16 deletions

File tree

v3/src/gameobjects/particles/ParticleEmitter.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -404,24 +404,26 @@ var ParticleEmitter = new Class({
404404
else
405405
{
406406
// Where source = Geom like Circle, or a Path or Curve
407-
// zone: { source: X, random: true }
408-
// zone: { source: X, edge: true, quantity: 32 }
407+
// zone: { type: 'random', source: X }
408+
// zone: { type: 'edge', source: X, quantity: 32, [stepRate=0], [yoyo=false] }
409409

410+
var type = GetFastValue(zone, 'type', 'random');
410411
var source = GetFastValue(zone, 'source', null);
411412

412413
if (source && typeof source.getPoint === 'function')
413414
{
414-
// Valid source, is it random or edge?
415-
if (GetFastValue(zone, 'random', null))
415+
switch (type)
416416
{
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);
417+
case 'random':
418+
this.zone = new RandomZone(source);
419+
break;
420+
421+
case 'edge':
422+
var quantity = GetFastValue(zone, 'quantity', 1);
423+
var stepRate = GetFastValue(zone, 'stepRate', 0);
424+
var yoyo = GetFastValue(zone, 'yoyo', false);
425+
this.zone = new EdgeZone(source, quantity, stepRate, yoyo);
426+
break;
425427
}
426428
}
427429
}

v3/src/gameobjects/particles/zones/EdgeZone.js

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,65 @@ var EdgeZone = new Class({
55

66
initialize:
77

8-
function EdgeZone (source, quantity, stepRate)
8+
function EdgeZone (source, quantity, stepRate, yoyo)
99
{
10+
if (yoyo === undefined) { yoyo = false; }
11+
1012
this.source = source;
1113

1214
this.points = source.getPoints(quantity, stepRate);
1315

14-
this.counter = 0;
16+
this.yoyo = yoyo;
17+
18+
this.counter = -1;
19+
20+
this._length = this.points.length;
21+
22+
// 0 = forwards, 1 = backwards
23+
this._direction = 0;
1524
},
1625

1726
getPoint: function (particle)
1827
{
28+
if (this._direction === 0)
29+
{
30+
this.counter++;
31+
32+
if (this.counter === this._length)
33+
{
34+
if (this.yoyo)
35+
{
36+
this._direction = 1;
37+
this.counter--;
38+
}
39+
else
40+
{
41+
this.counter = 0;
42+
}
43+
}
44+
}
45+
else
46+
{
47+
this.counter--;
48+
49+
if (this.counter === -1)
50+
{
51+
if (this.yoyo)
52+
{
53+
this._direction = 0;
54+
this.counter = 0;
55+
}
56+
else
57+
{
58+
this.counter = this._length - 1;
59+
}
60+
}
61+
}
62+
1963
var point = this.points[this.counter];
2064

2165
particle.x = point.x;
2266
particle.y = point.y;
23-
24-
this.counter = Wrap(this.counter + 1, 0, this.points.length - 1);
2567
}
2668

2769
});

0 commit comments

Comments
 (0)