Skip to content

Commit cb8b74e

Browse files
committed
Scale, rotation, alpha and all eases back in.
1 parent 956d59f commit cb8b74e

2 files changed

Lines changed: 31 additions & 151 deletions

File tree

v3/src/gameobjects/particles/Particle.js

Lines changed: 28 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ var Particle = new Class({
1616
this.x = 0;
1717
this.y = 0;
1818

19-
// Add Acceleration (and Bounce?)
20-
2119
this.velocityX = 0;
2220
this.velocityY = 0;
2321

@@ -43,109 +41,18 @@ var Particle = new Class({
4341
// ease data
4442
this.data = {
4543
tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
46-
alpha: { min: 1, max: 1 },
47-
angle: { min: 0, max: 0 },
48-
scaleX: { min: 1, max: 1 },
49-
scaleY: { min: 1, max: 1 }
50-
};
51-
52-
/*
53-
this.start = {
54-
tint: 0xFFFFFF,
55-
alpha: 1,
56-
scale: { x: 1, y: 1 },
57-
angle: 0
44+
alpha: { min: 1, max: 1, calc: 0 },
45+
angle: { min: 0, max: 0, calc: 0 },
46+
scaleX: { min: 1, max: 1, calc: 0 },
47+
scaleY: { min: 1, max: 1, calc: 0 }
5848
};
59-
60-
this.end = {
61-
tint: 0xFFFFFF,
62-
alpha: 1,
63-
scale: { x: 1, y: 1 },
64-
angle: 0
65-
};
66-
*/
67-
},
68-
69-
reset: function ()
70-
{
71-
this.index = 0;
72-
73-
// this.frame = frame;
74-
75-
this.x = 0;
76-
this.y = 0;
77-
78-
this.velocityX = 0;
79-
this.velocityY = 0;
80-
81-
this.life = 1000;
82-
this.lifeCurrent = 1000;
83-
84-
// this.scaleX = 1;
85-
// this.scaleY = 1;
86-
87-
// this.rotation = 0;
88-
89-
// this.color = 0xFFFFFFFF;
90-
91-
// this.life = 1;
92-
// this.lifeStep = 1;
93-
// this.normLifeStep = 1;
94-
95-
/*
96-
var start = this.start;
97-
98-
start.tint = 0xFFFFFF;
99-
start.alpha = 1;
100-
start.scale.x = 1;
101-
start.scale.y = 1;
102-
start.angle = 0;
103-
104-
var end = this.end;
105-
106-
end.tint = 0xFFFFFF;
107-
end.alpha = 1;
108-
end.scale.x = 1;
109-
end.scale.y = 1;
110-
end.angle = 0;
111-
*/
112-
113-
return this;
11449
},
11550

11651
isAlive: function ()
11752
{
11853
return (this.lifeCurrent > 0);
11954
},
12055

121-
// var rad = DegToRad(Between(this.minEmitAngle, this.maxEmitAngle));
122-
// var speed = Between(this.minSpeed, this.maxSpeed);
123-
// var vx = Math.cos(rad) * speed;
124-
// var vy = Math.sin(rad) * speed;
125-
126-
// particle.velocityX = vx;
127-
// particle.velocityY = vy;
128-
// particle.life = Math.max(this.life, Number.MIN_VALUE);
129-
// particle.lifeStep = particle.life;
130-
// particle.start.scale = this.startScale;
131-
// particle.end.scale = this.endScale;
132-
// particle.scaleX = this.startScale;
133-
// particle.scaleY = this.startScale;
134-
// particle.start.alpha = this.startAlpha;
135-
// particle.end.alpha = this.endAlpha;
136-
// particle.start.rotation = DegToRad(this.startAngle);
137-
// particle.end.rotation = DegToRad(this.endAngle);
138-
// particle.color = (particle.color & 0x00FFFFFF) | (((this.startAlpha * 0xFF)|0) << 24);
139-
// particle.index = this.alive.length;
140-
141-
// this.data = {
142-
// tint: { min: 0xffffff, max: 0xffffff, current: 0xffffff },
143-
// alpha: { min: 1, max: 1, current: 1 },
144-
// angle: { min: 0, max: 0, current: 0 },
145-
// scaleX: { min: 1, max: 1, current: 1 },
146-
// scaleY: { min: 1, max: 1, current: 1 }
147-
// };
148-
14956
emit: function (emitter)
15057
{
15158
this.frame = emitter.getFrame();
@@ -178,70 +85,47 @@ var Particle = new Class({
17885
this.lifeCurrent = this.life;
17986

18087
// eased values
181-
182-
// emitter.scale.copyXToMinMax(this.data.scaleX);
183-
// emitter.scale.copyYToMinMax(this.data.scaleY);
184-
185-
// emitter.particleAngle.copyToMinMax(this.data.angle);
186-
187-
// emitter.alpha.copyToMinMax(this.data.alpha);
188-
189-
// this.scaleX = emitter.scale.xMin;
190-
// this.scaleY = emitter.scale.yMin;
191-
192-
// this.rotation = DegToRad(emitter.particleAngle.min);
193-
194-
// Set the starting ease data
195-
196-
// emitter.scale.copyX(this.start.scale);
197-
// emitter.scale.copyY(this.end.scale);
198-
199-
// this.start.alpha = emitter.alpha.min;
200-
// this.end.alpha = emitter.alpha.max;
201-
202-
// this.start.rotation = emitter.particleAngle.min;
203-
// this.end.rotation = emitter.particleAngle.max;
204-
205-
// this.color = (this.color & 0x00ffffff) | (((this.start.alpha * 0xff) | 0) << 24);
88+
emitter.scale.copyXToMinMax(this.data.scaleX);
89+
emitter.scale.copyYToMinMax(this.data.scaleY);
90+
emitter.particleAngle.copyToMinMax(this.data.angle);
91+
emitter.alpha.copyToMinMax(this.data.alpha);
92+
93+
// Pre-calc ease values
94+
this.data.scaleX.calc = this.data.scaleX.max - this.data.scaleX.min;
95+
this.data.scaleY.calc = this.data.scaleY.max - this.data.scaleY.min;
96+
this.data.angle.calc = this.data.angle.max - this.data.angle.min;
97+
this.data.alpha.calc = this.data.alpha.max - this.data.alpha.min;
98+
99+
// Set initial values
100+
this.rotation = DegToRad(this.data.angle.min);
101+
this.alpha = this.data.alpha.min;
102+
this.color = (this.color & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
103+
this.scaleX = this.data.scaleX.min;
104+
this.scaleY = this.data.scaleY.min;
206105

207106
this.index = emitter.alive.length;
208107
},
209108

210-
// particle.velocityX += gravityX;
211-
// particle.velocityY += gravityY;
212-
// particle.x += particle.velocityX * emitterStep;
213-
// particle.y += particle.velocityY * emitterStep;
214-
// particle.normLifeStep = particle.lifeStep / particle.life;
215-
216-
// var norm = 1 - particle.normLifeStep;
217-
// var alphaEase = this.easingFunctionAlpha(norm);
218-
// var scaleEase = this.easingFunctionScale(norm);
219-
// var rotationEase = this.easingFunctionRotation(norm);
220-
// var alphaf = (particle.end.alpha - particle.start.alpha) * alphaEase + particle.start.alpha;
221-
// var scale = (particle.end.scale - particle.start.scale) * scaleEase + particle.start.scale;
222-
// var rotation = (particle.end.rotation - particle.start.rotation) * rotationEase + particle.start.rotation;
223-
224-
// particle.scaleX = particle.scaleY = scale;
225-
// particle.color = (particle.color & 0x00FFFFFF) | (((alphaf * 0xFF)|0) << 24);
226-
// particle.rotation = rotation;
227-
228109
// delta = ms, step = delta / 1000
229110
update: function (emitter, delta, step)
230111
{
231112
// How far along in life is this particle? (t = 0 to 1)
232-
// var t = this.lifeCurrent / this.life, 0, 1;
113+
var t = 1 - (this.lifeCurrent / this.life);
233114

234115
this.velocityX += (emitter.gravity.x * step);
235116
this.velocityY += (emitter.gravity.y * step);
236117

237118
this.x += this.velocityX * step;
238119
this.y += this.velocityY * step;
239120

240-
// scale
121+
this.scaleX = this.data.scaleX.calc * emitter.easingFunctionScale(t) + this.data.scaleX.min;
122+
this.scaleY = this.data.scaleY.calc * emitter.easingFunctionScale(t) + this.data.scaleY.min;
123+
124+
this.rotation = DegToRad(this.data.angle.calc * emitter.easingFunctionRotation(t) + this.data.angle.min);
241125

242-
// rotation
126+
this.alpha = this.data.alpha.calc * emitter.easingFunctionAlpha(t) + this.data.alpha.min;
243127

244-
// alpha
128+
this.color = (this.color & 0x00FFFFFF) | (((this.alpha * 0xFF) | 0) << 24);
245129

246130
this.lifeCurrent -= delta;
247131

v3/src/gameobjects/particles/ParticleEmitter.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ var ParticleEmitter = new Class({
8787
// Optional Particle emission zone - must be an object that supports a `getRandomPoint` function, such as a Rectangle, Circle, Path, etc.
8888
this.zone = null;
8989

90-
// this.easingFunctionAlpha = Easing.Linear;
91-
// this.easingFunctionScale = Easing.Linear;
92-
// this.easingFunctionRotation = Easing.Linear;
90+
this.easingFunctionAlpha = Easing.Linear;
91+
this.easingFunctionScale = Easing.Linear;
92+
this.easingFunctionRotation = Easing.Linear;
9393

9494
this.active = true;
9595
},
@@ -131,7 +131,6 @@ var ParticleEmitter = new Class({
131131
return this;
132132
},
133133

134-
/*
135134
setEase: function (easeName, easeParam)
136135
{
137136
var ease = GetEaseFunction(easeName, easeParam);
@@ -163,7 +162,6 @@ var ParticleEmitter = new Class({
163162

164163
return this;
165164
},
166-
*/
167165

168166
// Particle Emission
169167

@@ -430,8 +428,6 @@ var ParticleEmitter = new Class({
430428
if (dead.length > 0)
431429
{
432430
particle = dead.pop();
433-
434-
particle.reset();
435431
}
436432
else
437433
{

0 commit comments

Comments
 (0)