Skip to content

Commit 5616af9

Browse files
committed
Added MoveTo support
1 parent 48b0c6c commit 5616af9

2 files changed

Lines changed: 30 additions & 7 deletions

File tree

v3/src/gameobjects/particles/EmitterOp.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,13 @@ var EmitterOp = new Class({
225225

226226
steppedEmit: function ()
227227
{
228+
var current = this.counter;
229+
228230
var next = this.counter + ((this.end - this.start) / this.steps);
229231

230232
this.counter = Wrap(next, this.start, this.end);
231233

232-
return this.counter;
234+
return current;
233235
},
234236

235237
easedValueEmit: function (particle, key)

v3/src/gameobjects/particles/Particle.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var Class = require('../../utils/Class');
22
var DegToRad = require('../../math/DegToRad');
3+
var DistanceBetween = require('../../math/distance/DistanceBetween');
34

45
var Particle = new Class({
56

@@ -42,6 +43,7 @@ var Particle = new Class({
4243
this.scrollFactorX = 1;
4344
this.scrollFactorY = 1;
4445

46+
this.tint = 0xffffffff;
4547
this.color = 0xffffffff;
4648

4749
// in ms
@@ -107,6 +109,10 @@ var Particle = new Class({
107109
this.y += y;
108110
}
109111

112+
this.life = emitter.lifespan.onEmit(this, 'lifespan');
113+
this.lifeCurrent = this.life;
114+
this.lifeT = 0;
115+
110116
var sx = emitter.speedX.onEmit(this, 'speedX');
111117
var sy = (emitter.speedY) ? emitter.speedY.onEmit(this, 'speedY') : sx;
112118

@@ -117,6 +123,21 @@ var Particle = new Class({
117123
this.velocityX = Math.cos(rad) * Math.abs(sx);
118124
this.velocityY = Math.sin(rad) * Math.abs(sy);
119125
}
126+
else if (emitter.moveTo)
127+
{
128+
var mx = emitter.moveToX.onEmit(this, 'moveToX');
129+
var my = (emitter.moveToY) ? emitter.moveToY.onEmit(this, 'moveToY') : mx;
130+
131+
var angle = Math.atan2(my - this.y, mx - this.x);
132+
133+
var speed = DistanceBetween(this.x, this.y, mx, my) / (this.life / 1000);
134+
135+
// We know how many pixels we need to move, but how fast?
136+
// var speed = this.distanceToXY(displayObject, x, y) / (maxTime / 1000);
137+
138+
this.velocityX = Math.cos(angle) * speed;
139+
this.velocityY = Math.sin(angle) * speed;
140+
}
120141
else
121142
{
122143
this.velocityX = sx;
@@ -134,10 +155,6 @@ var Particle = new Class({
134155

135156
this.delayCurrent = emitter.delay.onEmit(this, 'delay');
136157

137-
this.life = emitter.lifespan.onEmit(this, 'lifespan');
138-
this.lifeCurrent = this.life;
139-
this.lifeT = 0;
140-
141158
this.scaleX = emitter.scaleX.onEmit(this, 'scaleX');
142159
this.scaleY = (emitter.scaleY) ? emitter.scaleY.onEmit(this, 'scaleY') : this.scaleX;
143160

@@ -148,7 +165,9 @@ var Particle = new Class({
148165

149166
this.alpha = emitter.alpha.onEmit(this, 'alpha');
150167

151-
this.color = (this.color & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
168+
this.tint = emitter.tint.onEmit(this, 'tint');
169+
170+
this.color = (this.tint & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
152171

153172
this.index = emitter.alive.length;
154173
},
@@ -276,7 +295,9 @@ var Particle = new Class({
276295

277296
this.alpha = emitter.alpha.onUpdate(this, 'alpha', t, this.alpha);
278297

279-
this.color = (this.color & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
298+
this.tint = emitter.tint.onUpdate(this, 'tint', t, this.tint);
299+
300+
this.color = (this.tint & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
280301

281302
this.lifeCurrent -= delta;
282303

0 commit comments

Comments
 (0)