melonjs 10.6.1 → 10.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/melonjs.js +37947 -36530
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +1352 -307
- package/dist/melonjs.module.js +2929 -1501
- package/package.json +14 -12
- package/src/camera/camera2d.js +1 -1
- package/src/entity/entity.js +6 -7
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +10 -11
- package/src/geometries/line.js +3 -3
- package/src/geometries/path2d.js +319 -0
- package/src/geometries/poly.js +11 -11
- package/src/geometries/rectangle.js +30 -15
- package/src/geometries/roundrect.js +67 -0
- package/src/index.js +9 -5
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +3 -4
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXObject.js +9 -12
- package/src/level/tiled/TMXTileMap.js +23 -4
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +5 -5
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +1 -1
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +130 -430
- package/src/particles/particle.js +53 -53
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +67 -51
- package/src/physics/bounds.js +8 -9
- package/src/physics/world.js +1 -1
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/collectable.js +9 -2
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +1 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/renderable.js +1 -1
- package/src/renderable/sprite.js +2 -3
- package/src/renderable/trigger.js +10 -4
- package/src/state/stage.js +1 -1
- package/src/state/state.js +8 -8
- package/src/system/device.js +148 -133
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +156 -149
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +1 -1
- package/src/text/text.js +1 -1
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +104 -36
- package/src/video/renderer.js +28 -16
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/glshader.js +30 -194
- package/src/video/webgl/utils/attributes.js +16 -0
- package/src/video/webgl/utils/precision.js +11 -0
- package/src/video/webgl/utils/program.js +58 -0
- package/src/video/webgl/utils/string.js +16 -0
- package/src/video/webgl/utils/uniforms.js +87 -0
- package/src/video/webgl/webgl_compositor.js +1 -14
- package/src/video/webgl/webgl_renderer.js +129 -186
- package/src/particles/particlecontainer.js +0 -95
package/src/particles/emitter.js
CHANGED
|
@@ -1,334 +1,81 @@
|
|
|
1
1
|
import { createCanvas } from "./../video/video.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import ParticleContainer from "./particlecontainer.js";
|
|
2
|
+
import pool from "./../system/pooling.js";
|
|
3
|
+
import ParticleEmitterSettings from "./settings.js";
|
|
5
4
|
import { randomFloat } from "./../math/math.js";
|
|
5
|
+
import Container from "./../renderable/container.js";
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var pixel = (function () {
|
|
11
|
-
var canvas = createCanvas(1, 1);
|
|
12
|
-
var context = canvas.getContext("2d");
|
|
13
|
-
context.fillStyle = "#fff";
|
|
14
|
-
context.fillRect(0, 0, 1, 1);
|
|
15
|
-
return canvas;
|
|
16
|
-
})();
|
|
8
|
+
// default texture used when no sprite is defined
|
|
9
|
+
let defaultParticleTexture;
|
|
17
10
|
|
|
18
11
|
/**
|
|
19
|
-
* me.ParticleEmitterSettings contains the default settings for me.ParticleEmitter
|
|
20
12
|
* @ignore
|
|
21
|
-
* @class
|
|
22
|
-
* @see ParticleEmitter
|
|
23
13
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
*/
|
|
33
|
-
width : 0,
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Height of the particle spawn area
|
|
37
|
-
* @public
|
|
38
|
-
* @type {number}
|
|
39
|
-
* @name height
|
|
40
|
-
* @memberof ParticleEmitterSettings
|
|
41
|
-
* @default 0
|
|
42
|
-
*/
|
|
43
|
-
height : 0,
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Image used for particles
|
|
47
|
-
* @public
|
|
48
|
-
* @type {CanvasImageSource}
|
|
49
|
-
* @name image
|
|
50
|
-
* @memberof ParticleEmitterSettings
|
|
51
|
-
* @default 1x1 white pixel
|
|
52
|
-
* @see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#canvasimagesource
|
|
53
|
-
*/
|
|
54
|
-
image : pixel,
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Total number of particles in the emitter
|
|
58
|
-
* @public
|
|
59
|
-
* @type {number}
|
|
60
|
-
* @name totalParticles
|
|
61
|
-
* @default 50
|
|
62
|
-
* @memberof ParticleEmitterSettings
|
|
63
|
-
*/
|
|
64
|
-
totalParticles : 50,
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Start angle for particle launch in Radians
|
|
68
|
-
* @public
|
|
69
|
-
* @type {number}
|
|
70
|
-
* @name angle
|
|
71
|
-
* @default Math.PI / 2
|
|
72
|
-
* @memberof ParticleEmitterSettings
|
|
73
|
-
*/
|
|
74
|
-
angle : Math.PI / 2,
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Variation in the start angle for particle launch in Radians
|
|
78
|
-
* @public
|
|
79
|
-
* @type {number}
|
|
80
|
-
* @name angleVariation
|
|
81
|
-
* @default 0
|
|
82
|
-
* @memberof ParticleEmitterSettings
|
|
83
|
-
*/
|
|
84
|
-
angleVariation : 0,
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Minimum time each particle lives once it is emitted in ms
|
|
88
|
-
* @public
|
|
89
|
-
* @type {number}
|
|
90
|
-
* @name minLife
|
|
91
|
-
* @default 1000
|
|
92
|
-
* @memberof ParticleEmitterSettings
|
|
93
|
-
*/
|
|
94
|
-
minLife : 1000,
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Maximum time each particle lives once it is emitted in ms
|
|
98
|
-
* @public
|
|
99
|
-
* @type {number}
|
|
100
|
-
* @name maxLife
|
|
101
|
-
* @default 3000
|
|
102
|
-
* @memberof ParticleEmitterSettings
|
|
103
|
-
*/
|
|
104
|
-
maxLife : 3000,
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Start speed of particles.<br>
|
|
108
|
-
* @public
|
|
109
|
-
* @type {number}
|
|
110
|
-
* @name speed
|
|
111
|
-
* @default 2
|
|
112
|
-
* @memberof ParticleEmitterSettings
|
|
113
|
-
*/
|
|
114
|
-
speed : 2,
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Variation in the start speed of particles
|
|
118
|
-
* @public
|
|
119
|
-
* @type {number}
|
|
120
|
-
* @name speedVariation
|
|
121
|
-
* @default 1
|
|
122
|
-
* @memberof ParticleEmitterSettings
|
|
123
|
-
*/
|
|
124
|
-
speedVariation : 1,
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Minimum start rotation for particles sprites in Radians
|
|
128
|
-
* @public
|
|
129
|
-
* @type {number}
|
|
130
|
-
* @name minRotation
|
|
131
|
-
* @default 0
|
|
132
|
-
* @memberof ParticleEmitterSettings
|
|
133
|
-
*/
|
|
134
|
-
minRotation : 0,
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Maximum start rotation for particles sprites in Radians
|
|
138
|
-
* @public
|
|
139
|
-
* @type {number}
|
|
140
|
-
* @name maxRotation
|
|
141
|
-
* @default 0
|
|
142
|
-
* @memberof ParticleEmitterSettings
|
|
143
|
-
*/
|
|
144
|
-
maxRotation : 0,
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Minimum start scale ratio for particles (1 = no scaling)
|
|
148
|
-
* @public
|
|
149
|
-
* @type {number}
|
|
150
|
-
* @name minStartScale
|
|
151
|
-
* @default 1
|
|
152
|
-
* @memberof ParticleEmitterSettings
|
|
153
|
-
*/
|
|
154
|
-
minStartScale : 1,
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Maximum start scale ratio for particles (1 = no scaling)
|
|
158
|
-
* @public
|
|
159
|
-
* @type {number}
|
|
160
|
-
* @name maxStartScale
|
|
161
|
-
* @default 1
|
|
162
|
-
* @memberof ParticleEmitterSettings
|
|
163
|
-
*/
|
|
164
|
-
maxStartScale : 1,
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Minimum end scale ratio for particles
|
|
168
|
-
* @public
|
|
169
|
-
* @type {number}
|
|
170
|
-
* @name minEndScale
|
|
171
|
-
* @default 0
|
|
172
|
-
* @memberof ParticleEmitterSettings
|
|
173
|
-
*/
|
|
174
|
-
minEndScale : 0,
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Maximum end scale ratio for particles
|
|
178
|
-
* @public
|
|
179
|
-
* @type {number}
|
|
180
|
-
* @name maxEndScale
|
|
181
|
-
* @default 0
|
|
182
|
-
* @memberof ParticleEmitterSettings
|
|
183
|
-
*/
|
|
184
|
-
maxEndScale : 0,
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Vertical force (Gravity) for each particle
|
|
188
|
-
* @public
|
|
189
|
-
* @type {number}
|
|
190
|
-
* @name gravity
|
|
191
|
-
* @default 0
|
|
192
|
-
* @memberof ParticleEmitterSettings
|
|
193
|
-
* @see game.world.gravity
|
|
194
|
-
*/
|
|
195
|
-
gravity : 0,
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Horizontal force (like a Wind) for each particle
|
|
199
|
-
* @public
|
|
200
|
-
* @type {number}
|
|
201
|
-
* @name wind
|
|
202
|
-
* @default 0
|
|
203
|
-
* @memberof ParticleEmitterSettings
|
|
204
|
-
*/
|
|
205
|
-
wind : 0,
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Update the rotation of particle in accordance the particle trajectory.<br>
|
|
209
|
-
* The particle sprite should aim at zero angle (draw from left to right).<br>
|
|
210
|
-
* Override the particle minRotation and maxRotation.<br>
|
|
211
|
-
* @public
|
|
212
|
-
* @type {boolean}
|
|
213
|
-
* @name followTrajectory
|
|
214
|
-
* @default false
|
|
215
|
-
* @memberof ParticleEmitterSettings
|
|
216
|
-
*/
|
|
217
|
-
followTrajectory : false,
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Enable the Texture Additive by canvas composite operation (lighter).<br>
|
|
221
|
-
* WARNING: Composite Operation may decreases performance!.<br>
|
|
222
|
-
* @public
|
|
223
|
-
* @type {boolean}
|
|
224
|
-
* @name textureAdditive
|
|
225
|
-
* @default false
|
|
226
|
-
* @memberof ParticleEmitterSettings
|
|
227
|
-
*/
|
|
228
|
-
textureAdditive : false,
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Update particles only in the viewport, remove it when out of viewport.<br>
|
|
232
|
-
* @public
|
|
233
|
-
* @type {boolean}
|
|
234
|
-
* @name onlyInViewport
|
|
235
|
-
* @default true
|
|
236
|
-
* @memberof ParticleEmitterSettings
|
|
237
|
-
*/
|
|
238
|
-
onlyInViewport : true,
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Render particles in screen space. <br>
|
|
242
|
-
* @public
|
|
243
|
-
* @type {boolean}
|
|
244
|
-
* @name floating
|
|
245
|
-
* @default false
|
|
246
|
-
* @memberof ParticleEmitterSettings
|
|
247
|
-
*/
|
|
248
|
-
floating : false,
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Maximum number of particles launched each time in this emitter (used only if emitter is Stream).<br>
|
|
252
|
-
* @public
|
|
253
|
-
* @type {number}
|
|
254
|
-
* @name maxParticles
|
|
255
|
-
* @default 10
|
|
256
|
-
* @memberof ParticleEmitterSettings
|
|
257
|
-
*/
|
|
258
|
-
maxParticles : 10,
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* How often a particle is emitted in ms (used only if emitter is Stream).<br>
|
|
262
|
-
* Necessary that value is greater than zero.<br>
|
|
263
|
-
* @public
|
|
264
|
-
* @type {number}
|
|
265
|
-
* @name frequency
|
|
266
|
-
* @default 100
|
|
267
|
-
* @memberof ParticleEmitterSettings
|
|
268
|
-
*/
|
|
269
|
-
frequency : 100,
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Duration that the emitter releases particles in ms (used only if emitter is Stream).<br>
|
|
273
|
-
* After this period, the emitter stop the launch of particles.<br>
|
|
274
|
-
* @public
|
|
275
|
-
* @type {number}
|
|
276
|
-
* @name duration
|
|
277
|
-
* @default Infinity
|
|
278
|
-
* @memberof ParticleEmitterSettings
|
|
279
|
-
*/
|
|
280
|
-
duration : Infinity,
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Skip n frames after updating the particle system once. <br>
|
|
284
|
-
* This can be used to reduce the performance impact of emitters with many particles.<br>
|
|
285
|
-
* @public
|
|
286
|
-
* @type {number}
|
|
287
|
-
* @name framesToSkip
|
|
288
|
-
* @default 0
|
|
289
|
-
* @memberof ParticleEmitterSettings
|
|
290
|
-
*/
|
|
291
|
-
framesToSkip : 0
|
|
14
|
+
function createDefaultParticleTexture(w = 8, h = 8) {
|
|
15
|
+
if (typeof defaultParticleTexture === "undefined") {
|
|
16
|
+
defaultParticleTexture = createCanvas(w, h, true);
|
|
17
|
+
var context = defaultParticleTexture.getContext("2d");
|
|
18
|
+
context.fillStyle = "#fff";
|
|
19
|
+
context.fillRect(0, 0, w, h);
|
|
20
|
+
}
|
|
21
|
+
return defaultParticleTexture;
|
|
292
22
|
};
|
|
293
23
|
|
|
294
24
|
/**
|
|
25
|
+
* @classdesc
|
|
295
26
|
* Particle Emitter Object.
|
|
296
|
-
* @
|
|
297
|
-
* @augments Rect
|
|
298
|
-
* @param {number} x x-position of the particle emitter
|
|
299
|
-
* @param {number} y y-position of the particle emitter
|
|
300
|
-
* @param {object} settings An object containing the settings for the particle emitter. See {@link ParticleEmitterSettings}
|
|
301
|
-
* @example
|
|
302
|
-
* // Create a basic emitter at position 100, 100
|
|
303
|
-
* var emitter = new me.ParticleEmitter(100, 100);
|
|
304
|
-
*
|
|
305
|
-
* // Adjust the emitter properties
|
|
306
|
-
* emitter.totalParticles = 200;
|
|
307
|
-
* emitter.minLife = 1000;
|
|
308
|
-
* emitter.maxLife = 3000;
|
|
309
|
-
* emitter.z = 10;
|
|
310
|
-
*
|
|
311
|
-
* // Add the emitter to the game world
|
|
312
|
-
* me.game.world.addChild(emitter);
|
|
313
|
-
*
|
|
314
|
-
* // Launch all particles one time and stop, like a explosion
|
|
315
|
-
* emitter.burstParticles();
|
|
316
|
-
*
|
|
317
|
-
* // Launch constantly the particles, like a fountain
|
|
318
|
-
* emitter.streamParticles();
|
|
319
|
-
*
|
|
320
|
-
* // At the end, remove emitter from the game world
|
|
321
|
-
* // call this in onDestroyEvent function
|
|
322
|
-
* me.game.world.removeChild(emitter);
|
|
27
|
+
* @augments Container
|
|
323
28
|
*/
|
|
324
|
-
class ParticleEmitter extends
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
* @
|
|
328
|
-
|
|
329
|
-
|
|
29
|
+
class ParticleEmitter extends Container {
|
|
30
|
+
/**
|
|
31
|
+
* @param {number} x x position of the particle emitter
|
|
32
|
+
* @param {number} y y position of the particle emitter
|
|
33
|
+
* @param {ParticleEmitterSettings} [settings=ParticleEmitterSettings] the settings for the particle emitter.
|
|
34
|
+
* @example
|
|
35
|
+
* // Create a particle emitter at position 100, 100
|
|
36
|
+
* var emitter = new ParticleEmitter(100, 100, {
|
|
37
|
+
* width: 16,
|
|
38
|
+
* height : 16,
|
|
39
|
+
* tint: "#f00",
|
|
40
|
+
* totalParticles: 32,
|
|
41
|
+
* angle: 0,
|
|
42
|
+
* angleVariation: 6.283185307179586,
|
|
43
|
+
* maxLife: 5,
|
|
44
|
+
* speed: 3
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Add the emitter to the game world
|
|
48
|
+
* me.game.world.addChild(emitter);
|
|
49
|
+
*
|
|
50
|
+
* // Launch all particles one time and stop, like a explosion
|
|
51
|
+
* emitter.burstParticles();
|
|
52
|
+
*
|
|
53
|
+
* // Launch constantly the particles, like a fountain
|
|
54
|
+
* emitter.streamParticles();
|
|
55
|
+
*
|
|
56
|
+
* // At the end, remove emitter from the game world
|
|
57
|
+
* // call this in onDestroyEvent function
|
|
58
|
+
* me.game.world.removeChild(emitter);
|
|
59
|
+
*/
|
|
60
|
+
constructor(x, y, settings = {}) {
|
|
330
61
|
// call the super constructor
|
|
331
|
-
super(
|
|
62
|
+
super(
|
|
63
|
+
x, y,
|
|
64
|
+
settings.width | 1,
|
|
65
|
+
settings.height | 1
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* the current (active) emitter settings
|
|
70
|
+
* @public
|
|
71
|
+
* @type {ParticleEmitterSettings}
|
|
72
|
+
* @name settings
|
|
73
|
+
* @memberof ParticleEmitter
|
|
74
|
+
*/
|
|
75
|
+
this.settings = {};
|
|
76
|
+
|
|
77
|
+
// center the emitter around the given coordinates
|
|
78
|
+
this.centerOn(x, y);
|
|
332
79
|
|
|
333
80
|
// Emitter is Stream, launch particles constantly
|
|
334
81
|
/** @ignore */
|
|
@@ -354,169 +101,95 @@ class ParticleEmitter extends Renderable {
|
|
|
354
101
|
// don't sort the particles by z-index
|
|
355
102
|
this.autoSort = false;
|
|
356
103
|
|
|
357
|
-
|
|
104
|
+
// count the updates
|
|
105
|
+
this._updateCount = 0;
|
|
358
106
|
|
|
359
|
-
//
|
|
360
|
-
this.
|
|
361
|
-
}
|
|
107
|
+
// internally store how much time was skipped when frames are skipped
|
|
108
|
+
this._dt = 0;
|
|
362
109
|
|
|
363
|
-
|
|
364
|
-
* @ignore
|
|
365
|
-
*/
|
|
366
|
-
get z() {
|
|
367
|
-
return this.container.pos.z;
|
|
368
|
-
}
|
|
110
|
+
//this.anchorPoint.set(0, 0);
|
|
369
111
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
*/
|
|
373
|
-
set z(value) {
|
|
374
|
-
this.container.pos.z = value;
|
|
112
|
+
// Reset the emitter to defaults
|
|
113
|
+
this.reset(settings);
|
|
375
114
|
}
|
|
376
115
|
|
|
377
116
|
/**
|
|
378
|
-
*
|
|
379
|
-
* @
|
|
380
|
-
* @name floating
|
|
381
|
-
* @memberof ParticleEmitter
|
|
117
|
+
* Reset the emitter with particle emitter settings.
|
|
118
|
+
* @param {ParticleEmitterSettings} settings [optional] object with emitter settings. See {@link ParticleEmitterSettings}
|
|
382
119
|
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
set floating(value) {
|
|
388
|
-
this.container.floating = value;
|
|
389
|
-
}
|
|
120
|
+
reset(settings = {}) {
|
|
121
|
+
Object.assign(this.settings, ParticleEmitterSettings, settings);
|
|
390
122
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
onActivateEvent() {
|
|
395
|
-
this.ancestor.addChild(this.container);
|
|
396
|
-
this.container.pos.z = this.pos.z;
|
|
397
|
-
if (!this.ancestor.autoSort) {
|
|
398
|
-
this.ancestor.sort();
|
|
123
|
+
// Cache the image reference
|
|
124
|
+
if (typeof this.settings.image === "undefined") {
|
|
125
|
+
this.settings.image = createDefaultParticleTexture(settings.textureSize, settings.textureSize);
|
|
399
126
|
}
|
|
400
|
-
}
|
|
401
127
|
|
|
402
|
-
|
|
403
|
-
* @ignore
|
|
404
|
-
*/
|
|
405
|
-
onDeactivateEvent() {
|
|
406
|
-
if (this.ancestor.hasChild(this.container)) {
|
|
407
|
-
this.ancestor.removeChildNow(this.container);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
128
|
+
this.floating = this.settings.floating;
|
|
410
129
|
|
|
411
|
-
|
|
412
|
-
* @ignore
|
|
413
|
-
*/
|
|
414
|
-
destroy() {
|
|
415
|
-
this.reset();
|
|
130
|
+
this.isDirty = true;
|
|
416
131
|
}
|
|
417
132
|
|
|
418
133
|
/**
|
|
419
|
-
* returns a random point
|
|
420
|
-
* @name getRandomPointX
|
|
421
|
-
* @memberof ParticleEmitter
|
|
422
|
-
* @function
|
|
134
|
+
* returns a random point on the x axis within the bounds of this emitter
|
|
423
135
|
* @returns {number}
|
|
424
136
|
*/
|
|
425
137
|
getRandomPointX() {
|
|
426
|
-
return
|
|
138
|
+
return randomFloat(0, this.getBounds().width);
|
|
427
139
|
}
|
|
428
140
|
|
|
429
141
|
/**
|
|
430
|
-
* returns a random point
|
|
431
|
-
* @name getRandomPointY
|
|
432
|
-
* @memberof ParticleEmitter
|
|
433
|
-
* @function
|
|
142
|
+
* returns a random point on the y axis within the bounds this emitter
|
|
434
143
|
* @returns {number}
|
|
435
144
|
*/
|
|
436
145
|
getRandomPointY() {
|
|
437
|
-
return
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Reset the emitter with default values.<br>
|
|
442
|
-
* @function
|
|
443
|
-
* @param {object} settings [optional] object with emitter settings. See {@link ParticleEmitterSettings}
|
|
444
|
-
* @name reset
|
|
445
|
-
* @memberof ParticleEmitter
|
|
446
|
-
*/
|
|
447
|
-
reset(settings) {
|
|
448
|
-
// check if settings exists and create a dummy object if necessary
|
|
449
|
-
settings = settings || {};
|
|
450
|
-
var defaults = ParticleEmitterSettings;
|
|
451
|
-
|
|
452
|
-
var width = (typeof settings.width === "number") ? settings.width : defaults.width;
|
|
453
|
-
var height = (typeof settings.height === "number") ? settings.height : defaults.height;
|
|
454
|
-
this.resize(width, height);
|
|
455
|
-
|
|
456
|
-
Object.assign(this, defaults, settings);
|
|
457
|
-
|
|
458
|
-
// reset particle container values
|
|
459
|
-
this.container.reset();
|
|
146
|
+
return randomFloat(0, this.getBounds().height);
|
|
460
147
|
}
|
|
461
148
|
|
|
462
149
|
// Add count particles in the game world
|
|
463
150
|
/** @ignore */
|
|
464
151
|
addParticles(count) {
|
|
465
|
-
for (var i = 0; i <
|
|
152
|
+
for (var i = 0; i < count; i++) {
|
|
466
153
|
// Add particle to the container
|
|
467
|
-
|
|
468
|
-
this.container.addChild(particle);
|
|
154
|
+
this.addChild(pool.pull("Particle", this), this.pos.z);
|
|
469
155
|
}
|
|
156
|
+
this.isDirty = true;
|
|
470
157
|
}
|
|
471
158
|
|
|
472
159
|
/**
|
|
473
|
-
* Emitter is of type stream and is launching particles
|
|
474
|
-
* @function
|
|
160
|
+
* Emitter is of type stream and is launching particles
|
|
475
161
|
* @returns {boolean} Emitter is Stream and is launching particles
|
|
476
|
-
* @name isRunning
|
|
477
|
-
* @memberof ParticleEmitter
|
|
478
162
|
*/
|
|
479
163
|
isRunning() {
|
|
480
164
|
return this._enabled && this._stream;
|
|
481
165
|
}
|
|
482
166
|
|
|
483
167
|
/**
|
|
484
|
-
* Launch particles from emitter constantly
|
|
485
|
-
* Particles example: Fountains
|
|
168
|
+
* Launch particles from emitter constantly (e.g. for stream)
|
|
486
169
|
* @param {number} duration [optional] time that the emitter releases particles in ms
|
|
487
|
-
* @function
|
|
488
|
-
* @name streamParticles
|
|
489
|
-
* @memberof ParticleEmitter
|
|
490
170
|
*/
|
|
491
171
|
streamParticles(duration) {
|
|
492
172
|
this._enabled = true;
|
|
493
173
|
this._stream = true;
|
|
494
|
-
this.frequency = Math.max(this.frequency
|
|
495
|
-
this._durationTimer = (typeof duration === "number") ? duration : this.duration;
|
|
174
|
+
this.settings.frequency = Math.max(1, this.settings.frequency);
|
|
175
|
+
this._durationTimer = (typeof duration === "number") ? duration : this.settings.duration;
|
|
496
176
|
}
|
|
497
177
|
|
|
498
178
|
/**
|
|
499
|
-
* Stop the emitter from generating new particles (used only if emitter is Stream)
|
|
500
|
-
* @function
|
|
501
|
-
* @name stopStream
|
|
502
|
-
* @memberof ParticleEmitter
|
|
179
|
+
* Stop the emitter from generating new particles (used only if emitter is Stream)
|
|
503
180
|
*/
|
|
504
181
|
stopStream() {
|
|
505
182
|
this._enabled = false;
|
|
506
183
|
}
|
|
507
184
|
|
|
508
185
|
/**
|
|
509
|
-
* Launch all particles from emitter and stop
|
|
510
|
-
* Particles example: Explosions <br>
|
|
186
|
+
* Launch all particles from emitter and stop (e.g. for explosion)
|
|
511
187
|
* @param {number} total [optional] number of particles to launch
|
|
512
|
-
* @function
|
|
513
|
-
* @name burstParticles
|
|
514
|
-
* @memberof ParticleEmitter
|
|
515
188
|
*/
|
|
516
189
|
burstParticles(total) {
|
|
517
190
|
this._enabled = true;
|
|
518
191
|
this._stream = false;
|
|
519
|
-
this.addParticles((typeof total === "number") ? total : this.totalParticles);
|
|
192
|
+
this.addParticles((typeof total === "number") ? total : this.settings.totalParticles);
|
|
520
193
|
this._enabled = false;
|
|
521
194
|
}
|
|
522
195
|
|
|
@@ -524,6 +197,22 @@ class ParticleEmitter extends Renderable {
|
|
|
524
197
|
* @ignore
|
|
525
198
|
*/
|
|
526
199
|
update(dt) {
|
|
200
|
+
// skip frames if necessary
|
|
201
|
+
if (++this._updateCount > this.settings.framesToSkip) {
|
|
202
|
+
this._updateCount = 0;
|
|
203
|
+
}
|
|
204
|
+
if (this._updateCount > 0) {
|
|
205
|
+
this._dt += dt;
|
|
206
|
+
return this.isDirty;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// apply skipped delta time
|
|
210
|
+
dt += this._dt;
|
|
211
|
+
this._dt = 0;
|
|
212
|
+
|
|
213
|
+
// Update particles
|
|
214
|
+
this.isDirty |= super.update(dt);
|
|
215
|
+
|
|
527
216
|
// Launch new particles, if emitter is Stream
|
|
528
217
|
if ((this._enabled) && (this._stream)) {
|
|
529
218
|
// Check if the emitter has duration set
|
|
@@ -532,7 +221,7 @@ class ParticleEmitter extends Renderable {
|
|
|
532
221
|
|
|
533
222
|
if (this._durationTimer <= 0) {
|
|
534
223
|
this.stopStream();
|
|
535
|
-
return
|
|
224
|
+
return this.isDirty;
|
|
536
225
|
}
|
|
537
226
|
}
|
|
538
227
|
|
|
@@ -540,21 +229,32 @@ class ParticleEmitter extends Renderable {
|
|
|
540
229
|
this._frequencyTimer += dt;
|
|
541
230
|
|
|
542
231
|
// Check for new particles launch
|
|
543
|
-
var particlesCount = this.
|
|
544
|
-
if ((particlesCount < this.totalParticles) && (this._frequencyTimer >= this.frequency)) {
|
|
545
|
-
if ((particlesCount + this.maxParticles) <= this.totalParticles) {
|
|
546
|
-
this.addParticles(this.maxParticles);
|
|
232
|
+
var particlesCount = this.children.length;
|
|
233
|
+
if ((particlesCount < this.settings.totalParticles) && (this._frequencyTimer >= this.settings.frequency)) {
|
|
234
|
+
if ((particlesCount + this.settings.maxParticles) <= this.settings.totalParticles) {
|
|
235
|
+
this.addParticles(this.settings.maxParticles);
|
|
547
236
|
}
|
|
548
237
|
else {
|
|
549
|
-
this.addParticles(this.totalParticles - particlesCount);
|
|
238
|
+
this.addParticles(this.settings.totalParticles - particlesCount);
|
|
550
239
|
}
|
|
551
|
-
|
|
552
240
|
this._frequencyTimer = 0;
|
|
241
|
+
this.isDirty = true;
|
|
553
242
|
}
|
|
554
243
|
}
|
|
555
|
-
return
|
|
244
|
+
return this.isDirty;
|
|
556
245
|
}
|
|
557
246
|
|
|
247
|
+
/**
|
|
248
|
+
* Destroy function
|
|
249
|
+
* @ignore
|
|
250
|
+
*/
|
|
251
|
+
destroy() {
|
|
252
|
+
// call the parent destroy method
|
|
253
|
+
super.destroy(arguments);
|
|
254
|
+
// clean emitter specific Properties
|
|
255
|
+
this.settings.image = undefined;
|
|
256
|
+
this.settings = undefined;
|
|
257
|
+
}
|
|
558
258
|
};
|
|
559
259
|
|
|
560
|
-
export
|
|
260
|
+
export default ParticleEmitter;
|