melonjs 10.5.2 → 10.7.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.
Files changed (67) hide show
  1. package/README.md +4 -6
  2. package/dist/melonjs.js +37470 -36394
  3. package/dist/melonjs.min.js +22 -22
  4. package/dist/melonjs.module.d.ts +606 -426
  5. package/dist/melonjs.module.js +8114 -7033
  6. package/package.json +15 -13
  7. package/src/camera/camera2d.js +11 -10
  8. package/src/game.js +5 -5
  9. package/src/geometries/ellipse.js +1 -1
  10. package/src/geometries/poly.js +1 -1
  11. package/src/geometries/rectangle.js +15 -0
  12. package/src/index.js +5 -5
  13. package/src/input/gamepad.js +12 -10
  14. package/src/input/keyboard.js +5 -3
  15. package/src/input/pointer.js +1 -1
  16. package/src/input/pointerevent.js +3 -4
  17. package/src/level/tiled/TMXLayer.js +1 -1
  18. package/src/level/tiled/TMXTileMap.js +1 -1
  19. package/src/level/tiled/TMXUtils.js +1 -1
  20. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  21. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  22. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  23. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  24. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  25. package/src/loader/loader.js +1 -1
  26. package/src/loader/loadingscreen.js +1 -1
  27. package/src/math/color.js +1 -1
  28. package/src/math/matrix2.js +2 -2
  29. package/src/math/matrix3.js +67 -66
  30. package/src/math/observable_vector2.js +1 -1
  31. package/src/math/observable_vector3.js +1 -1
  32. package/src/math/vector2.js +1 -1
  33. package/src/math/vector3.js +1 -1
  34. package/src/particles/emitter.js +120 -429
  35. package/src/particles/particle.js +51 -52
  36. package/src/particles/settings.js +310 -0
  37. package/src/physics/body.js +7 -7
  38. package/src/polyfill/console.js +7 -7
  39. package/src/polyfill/index.js +7 -0
  40. package/src/polyfill/performance.js +20 -0
  41. package/src/polyfill/requestAnimationFrame.js +10 -10
  42. package/src/renderable/colorlayer.js +1 -1
  43. package/src/renderable/container.js +11 -1
  44. package/src/renderable/imagelayer.js +3 -3
  45. package/src/renderable/nineslicesprite.js +6 -3
  46. package/src/renderable/renderable.js +18 -1
  47. package/src/renderable/sprite.js +2 -2
  48. package/src/state/state.js +13 -13
  49. package/src/system/device.js +141 -128
  50. package/src/system/event.js +10 -10
  51. package/src/system/pooling.js +150 -155
  52. package/src/system/timer.js +1 -1
  53. package/src/text/bitmaptext.js +35 -91
  54. package/src/text/text.js +82 -145
  55. package/src/text/textmetrics.js +168 -0
  56. package/src/text/textstyle.js +14 -0
  57. package/src/utils/agent.js +4 -4
  58. package/src/utils/function.js +2 -2
  59. package/src/utils/utils.js +10 -5
  60. package/src/video/canvas/canvas_renderer.js +34 -4
  61. package/src/video/renderer.js +3 -5
  62. package/src/video/texture.js +1 -1
  63. package/src/video/video.js +11 -11
  64. package/src/video/webgl/buffer/vertex.js +0 -3
  65. package/src/video/webgl/glshader.js +1 -3
  66. package/src/video/webgl/webgl_renderer.js +50 -22
  67. package/src/particles/particlecontainer.js +0 -95
@@ -3,101 +3,108 @@ import timer from "./../system/timer.js";
3
3
  import { randomFloat, clamp } from "./../math/math.js";
4
4
  import Renderable from "./../renderable/renderable.js";
5
5
 
6
-
7
6
  /**
8
7
  * @classdesc
9
8
  * Single Particle Object.
10
- * @class Particle
11
9
  * @augments Renderable
12
- * @param {ParticleEmitter} particle emitter
13
10
  */
14
11
  class Particle extends Renderable {
15
12
  /**
16
- * @ignore
13
+ * @param {ParticleEmitter} emitter the particle emitter
17
14
  */
18
15
  constructor(emitter) {
19
16
  // Call the super constructor
20
17
  super(
21
18
  emitter.getRandomPointX(),
22
19
  emitter.getRandomPointY(),
23
- emitter.image.width,
24
- emitter.image.height
20
+ emitter.settings.image.width,
21
+ emitter.settings.image.height
25
22
  );
26
-
27
- // particle velocity
28
- this.vel = new Vector2d();
29
23
  this.onResetEvent(emitter, true);
30
24
  }
31
25
 
26
+ /**
27
+ * @ignore
28
+ */
32
29
  onResetEvent(emitter, newInstance = false) {
33
30
  if (newInstance === false) {
34
- super.onResetEvent(
31
+ this.pos.set(
35
32
  emitter.getRandomPointX(),
36
- emitter.getRandomPointY(),
37
- emitter.image.width,
38
- emitter.image.height
33
+ emitter.getRandomPointY()
39
34
  );
35
+ this.resize(
36
+ emitter.settings.image.width,
37
+ emitter.settings.image.height
38
+ );
39
+ } else {
40
+ // particle velocity
41
+ this.vel = new Vector2d();
40
42
  }
41
43
 
44
+ this.image = emitter.settings.image;
45
+
42
46
  // Particle will always update
43
47
  this.alwaysUpdate = true;
44
48
 
45
- // Cache the image reference
46
- this.image = emitter.image;
49
+ if (typeof emitter.settings.tint === "string") {
50
+ this.tint.parseCSS(emitter.settings.tint);
51
+ }
52
+
53
+ if (emitter.settings.textureAdditive === true) {
54
+ this.blendMode = "additive";
55
+ }
56
+
57
+ if (emitter.settings.blendMode !== "normal") {
58
+ this.blendMode = emitter.settings.blendMode;
59
+ }
47
60
 
48
61
  // Set the start particle Angle and Speed as defined in emitter
49
- var angle = emitter.angle + ((emitter.angleVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.angleVariation : 0);
50
- var speed = emitter.speed + ((emitter.speedVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.speedVariation : 0);
62
+ var angle = emitter.settings.angle + ((emitter.settings.angleVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.angleVariation : 0);
63
+ var speed = emitter.settings.speed + ((emitter.settings.speedVariation > 0) ? (randomFloat(0, 2) - 1) * emitter.settings.speedVariation : 0);
51
64
 
52
65
  // Set the start particle Velocity
53
66
  this.vel.set(speed * Math.cos(angle), -speed * Math.sin(angle));
54
67
 
55
68
  // Set the start particle Time of Life as defined in emitter
56
- this.life = randomFloat(emitter.minLife, emitter.maxLife);
69
+ this.life = randomFloat(emitter.settings.minLife, emitter.settings.maxLife);
57
70
  this.startLife = this.life;
58
71
 
59
72
  // Set the start and end particle Scale as defined in emitter
60
73
  // clamp the values as minimum and maximum scales range
61
74
  this.startScale = clamp(
62
- randomFloat(emitter.minStartScale, emitter.maxStartScale),
63
- emitter.minStartScale,
64
- emitter.maxStartScale
75
+ randomFloat(emitter.settings.minStartScale, emitter.settings.maxStartScale),
76
+ emitter.settings.minStartScale,
77
+ emitter.settings.maxStartScale
65
78
  );
66
79
  this.endScale = clamp(
67
- randomFloat(emitter.minEndScale, emitter.maxEndScale),
68
- emitter.minEndScale,
69
- emitter.maxEndScale
80
+ randomFloat(emitter.settings.minEndScale, emitter.settings.maxEndScale),
81
+ emitter.settings.minEndScale,
82
+ emitter.settings.maxEndScale
70
83
  );
71
84
 
72
85
  // Set the particle Gravity and Wind (horizontal gravity) as defined in emitter
73
- this.gravity = emitter.gravity;
74
- this.wind = emitter.wind;
86
+ this.gravity = emitter.settings.gravity;
87
+ this.wind = emitter.settings.wind;
75
88
 
76
89
  // Set if the particle update the rotation in accordance the trajectory
77
- this.followTrajectory = emitter.followTrajectory;
90
+ this.followTrajectory = emitter.settings.followTrajectory;
78
91
 
79
92
  // Set if the particle update only in Viewport
80
- this.onlyInViewport = emitter.onlyInViewport;
81
-
82
- // Set the particle Z Order
83
- this.pos.z = emitter.z;
93
+ this.onlyInViewport = emitter.settings.onlyInViewport;
84
94
 
85
95
  // cache inverse of the expected delta time
86
96
  this._deltaInv = timer.maxfps / 1000;
87
97
 
88
98
  // Set the start particle rotation as defined in emitter
89
99
  // if the particle not follow trajectory
90
- if (!emitter.followTrajectory) {
91
- this.angle = randomFloat(emitter.minRotation, emitter.maxRotation);
100
+ if (!emitter.settings.followTrajectory) {
101
+ this.angle = randomFloat(emitter.settings.minRotation, emitter.settings.maxRotation);
92
102
  }
93
103
  }
94
104
 
95
105
  /**
96
106
  * Update the Particle <br>
97
107
  * This is automatically called by the game manager {@link game}
98
- * @name update
99
- * @memberof Particle
100
- * @function
101
108
  * @ignore
102
109
  * @param {number} dt time since the last update in milliseconds
103
110
  */
@@ -108,6 +115,11 @@ class Particle extends Renderable {
108
115
  // Decrease particle life
109
116
  this.life = this.life > dt ? this.life - dt : 0;
110
117
 
118
+ if (this.life <= 0) {
119
+ this.ancestor.removeChild(this);
120
+ return false;
121
+ }
122
+
111
123
  // Calculate the particle Age Ratio
112
124
  var ageRatio = this.life / this.startLife;
113
125
 
@@ -142,23 +154,10 @@ class Particle extends Renderable {
142
154
  this.pos.x, this.pos.y, 1
143
155
  ).rotate(angle);
144
156
 
145
- // Return true if the particle is not dead yet
146
- return (this.inViewport || !this.onlyInViewport) && (this.life > 0);
147
- }
148
-
149
- /**
150
- * @ignore
151
- */
152
- preDraw(renderer) {
153
-
154
- // restore is called in postDraw
155
- renderer.save();
156
-
157
- // particle alpha value
158
- renderer.setGlobalAlpha(renderer.globalAlpha() * this.alpha);
157
+ // mark as dirty if the particle is not dead yet
158
+ this.isDirty = this.inViewport || !this.onlyInViewport;
159
159
 
160
- // translate to the defined anchor point and scale it
161
- renderer.transform(this.currentTransform);
160
+ return super.update(dt);
162
161
  }
163
162
 
164
163
  /**
@@ -0,0 +1,310 @@
1
+ /**
2
+ * ParticleEmitterSettings contains the default settings for ParticleEmitter
3
+ * @see ParticleEmitter
4
+ * @namespace ParticleEmitterSettings
5
+ */
6
+ const ParticleEmitterSettings = {
7
+ /**
8
+ * Width of the particle spawn area.
9
+ * @type {number}
10
+ * @name width
11
+ * @memberof ParticleEmitterSettings
12
+ * @default 1
13
+ */
14
+ width : 1,
15
+
16
+ /**
17
+ * Height of the particle spawn area
18
+ * @public
19
+ * @type {number}
20
+ * @name height
21
+ * @memberof ParticleEmitterSettings
22
+ * @default 1
23
+ */
24
+ height : 1,
25
+
26
+ /**
27
+ * image used for particles texture
28
+ * (by default melonJS will create an white 8x8 texture image)
29
+ * @public
30
+ * @type {HTMLCanvasElement}
31
+ * @name image
32
+ * @memberof ParticleEmitterSettings
33
+ * @default undefined
34
+ * @see ParticleEmitterSettings.textureSize
35
+ */
36
+ image : undefined,
37
+
38
+ /**
39
+ * default texture size used for particles if no image is specified
40
+ * (by default melonJS will create an white 8x8 texture image)
41
+ * @public
42
+ * @type {number}
43
+ * @name textureSize
44
+ * @memberof ParticleEmitterSettings
45
+ * @default 8
46
+ * @see ParticleEmitterSettings.image
47
+ */
48
+ textureSize : 8,
49
+
50
+ /**
51
+ * tint to be applied to particles
52
+ * @public
53
+ * @type {string}
54
+ * @name tint
55
+ * @memberof ParticleEmitterSettings
56
+ * @default "#fff"
57
+ */
58
+ tint : "#fff",
59
+
60
+ /**
61
+ * Total number of particles in the emitter
62
+ * @public
63
+ * @type {number}
64
+ * @name totalParticles
65
+ * @default 50
66
+ * @memberof ParticleEmitterSettings
67
+ */
68
+ totalParticles : 50,
69
+
70
+ /**
71
+ * Start angle for particle launch in Radians
72
+ * @public
73
+ * @type {number}
74
+ * @name angle
75
+ * @default Math.PI / 2
76
+ * @memberof ParticleEmitterSettings
77
+ */
78
+ angle : Math.PI / 2,
79
+
80
+ /**
81
+ * Variation in the start angle for particle launch in Radians.
82
+ * @public
83
+ * @type {number}
84
+ * @name angleVariation
85
+ * @default 0
86
+ * @memberof ParticleEmitterSettings
87
+ */
88
+ angleVariation : 0,
89
+
90
+ /**
91
+ * Minimum time each particle lives once it is emitted in ms.
92
+ * @public
93
+ * @type {number}
94
+ * @name minLife
95
+ * @default 1000
96
+ * @memberof ParticleEmitterSettings
97
+ */
98
+ minLife : 1000,
99
+
100
+ /**
101
+ * Maximum time each particle lives once it is emitted in ms.
102
+ * @public
103
+ * @type {number}
104
+ * @name maxLife
105
+ * @default 3000
106
+ * @memberof ParticleEmitterSettings
107
+ */
108
+ maxLife : 3000,
109
+
110
+ /**
111
+ * Start speed of particles.<br>
112
+ * @public
113
+ * @type {number}
114
+ * @name speed
115
+ * @default 2
116
+ * @memberof ParticleEmitterSettings
117
+ */
118
+ speed : 2,
119
+
120
+ /**
121
+ * Variation in the start speed of particles
122
+ * @public
123
+ * @type {number}
124
+ * @name speedVariation
125
+ * @default 1
126
+ * @memberof ParticleEmitterSettings
127
+ */
128
+ speedVariation : 1,
129
+
130
+ /**
131
+ * Minimum start rotation for particles sprites in Radians
132
+ * @public
133
+ * @type {number}
134
+ * @name minRotation
135
+ * @default 0
136
+ * @memberof ParticleEmitterSettings
137
+ */
138
+ minRotation : 0,
139
+
140
+ /**
141
+ * Maximum start rotation for particles sprites in Radians
142
+ * @public
143
+ * @type {number}
144
+ * @name maxRotation
145
+ * @default 0
146
+ * @memberof ParticleEmitterSettings
147
+ */
148
+ maxRotation : 0,
149
+
150
+ /**
151
+ * Minimum start scale ratio for particles (1 = no scaling)
152
+ * @public
153
+ * @type {number}
154
+ * @name minStartScale
155
+ * @default 1
156
+ * @memberof ParticleEmitterSettings
157
+ */
158
+ minStartScale : 1,
159
+
160
+ /**
161
+ * Maximum start scale ratio for particles (1 = no scaling)
162
+ * @public
163
+ * @type {number}
164
+ * @name maxStartScale
165
+ * @default 1
166
+ * @memberof ParticleEmitterSettings
167
+ */
168
+ maxStartScale : 1,
169
+
170
+ /**
171
+ * Minimum end scale ratio for particles
172
+ * @public
173
+ * @type {number}
174
+ * @name minEndScale
175
+ * @default 0
176
+ * @memberof ParticleEmitterSettings
177
+ */
178
+ minEndScale : 0,
179
+
180
+ /**
181
+ * Maximum end scale ratio for particles
182
+ * @public
183
+ * @type {number}
184
+ * @name maxEndScale
185
+ * @default 0
186
+ * @memberof ParticleEmitterSettings
187
+ */
188
+ maxEndScale : 0,
189
+
190
+ /**
191
+ * Vertical force (Gravity) for each particle
192
+ * @public
193
+ * @type {number}
194
+ * @name gravity
195
+ * @default 0
196
+ * @memberof ParticleEmitterSettings
197
+ * @see game.world.gravity
198
+ */
199
+ gravity : 0,
200
+
201
+ /**
202
+ * Horizontal force (like a Wind) for each particle
203
+ * @public
204
+ * @type {number}
205
+ * @name wind
206
+ * @default 0
207
+ * @memberof ParticleEmitterSettings
208
+ */
209
+ wind : 0,
210
+
211
+ /**
212
+ * Update the rotation of particle in accordance the particle trajectory.<br>
213
+ * The particle sprite should aim at zero angle (draw from left to right).<br>
214
+ * Override the particle minRotation and maxRotation.<br>
215
+ * @public
216
+ * @type {boolean}
217
+ * @name followTrajectory
218
+ * @default false
219
+ * @memberof ParticleEmitterSettings
220
+ */
221
+ followTrajectory : false,
222
+
223
+ /**
224
+ * Enable the Texture Additive by composite operation ("additive" blendMode)
225
+ * @public
226
+ * @type {boolean}
227
+ * @name textureAdditive
228
+ * @default false
229
+ * @memberof ParticleEmitterSettings
230
+ * @see ParticleEmitterSettings.blendMode
231
+ */
232
+ textureAdditive : false,
233
+
234
+ /**
235
+ * the blend mode to be applied when rendering particles.
236
+ * (note: this will superseed the `textureAdditive` setting if different than "normal")
237
+ * @public
238
+ * @type {string}
239
+ * @name blendMode
240
+ * @default normal
241
+ * @memberof ParticleEmitterSettings
242
+ * @see CanvasRenderer#setBlendMode
243
+ * @see WebGLRenderer#setBlendMode
244
+ */
245
+ blendMode : "normal",
246
+
247
+ /**
248
+ * Update particles only in the viewport, remove it when out of viewport.
249
+ * @public
250
+ * @type {boolean}
251
+ * @name onlyInViewport
252
+ * @default true
253
+ * @memberof ParticleEmitterSettings
254
+ */
255
+ onlyInViewport : true,
256
+
257
+ /**
258
+ * Render particles in screen space.
259
+ * @public
260
+ * @type {boolean}
261
+ * @name floating
262
+ * @default false
263
+ * @memberof ParticleEmitterSettings
264
+ */
265
+ floating : false,
266
+
267
+ /**
268
+ * Maximum number of particles launched each time in this emitter (used only if emitter is Stream).
269
+ * @public
270
+ * @type {number}
271
+ * @name maxParticles
272
+ * @default 10
273
+ * @memberof ParticleEmitterSettings
274
+ */
275
+ maxParticles : 10,
276
+
277
+ /**
278
+ * How often a particle is emitted in ms (used only if emitter is a Stream).
279
+ * @public
280
+ * @type {number}
281
+ * @name frequency
282
+ * @default 100
283
+ * @memberof ParticleEmitterSettings
284
+ */
285
+ frequency : 100,
286
+
287
+ /**
288
+ * Duration that the emitter releases particles in ms (used only if emitter is Stream).
289
+ * After this period, the emitter stop the launch of particles.
290
+ * @public
291
+ * @type {number}
292
+ * @name duration
293
+ * @default Infinity
294
+ * @memberof ParticleEmitterSettings
295
+ */
296
+ duration : Infinity,
297
+
298
+ /**
299
+ * Skip n frames after updating the particle system once.
300
+ * This can be used to reduce the performance impact of emitters with many particles.
301
+ * @public
302
+ * @type {number}
303
+ * @name framesToSkip
304
+ * @default 0
305
+ * @memberof ParticleEmitterSettings
306
+ */
307
+ framesToSkip : 0
308
+ };
309
+
310
+ export default ParticleEmitterSettings;
@@ -67,7 +67,7 @@ class Body {
67
67
  * @see collision.types
68
68
  * @example
69
69
  * // set the body collision type
70
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
70
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
71
71
  */
72
72
  this.collisionType = collision.types.ENEMY_OBJECT;
73
73
 
@@ -404,17 +404,17 @@ class Body {
404
404
  }
405
405
 
406
406
  /**
407
- * By default all entities are able to collide with all other entities, <br>
407
+ * By default all physic bodies are able to collide with all other bodies, <br>
408
408
  * but it's also possible to specify 'collision filters' to provide a finer <br>
409
- * control over which entities can collide with each other.
409
+ * control over which body can collide with each other.
410
410
  * @see collision.types
411
411
  * @param {number} [bitmask = collision.types.ALL_OBJECT] the collision mask
412
412
  * @example
413
413
  * // filter collision detection with collision shapes, enemies and collectables
414
- * myEntity.body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
414
+ * body.setCollisionMask(me.collision.types.WORLD_SHAPE | me.collision.types.ENEMY_OBJECT | me.collision.types.COLLECTABLE_OBJECT);
415
415
  * ...
416
416
  * // disable collision detection with all other objects
417
- * myEntity.body.setCollisionMask(me.collision.types.NO_OBJECT);
417
+ * body.setCollisionMask(me.collision.types.NO_OBJECT);
418
418
  */
419
419
  setCollisionMask(bitmask = collision.types.ALL_OBJECT) {
420
420
  this.collisionMask = bitmask;
@@ -426,7 +426,7 @@ class Body {
426
426
  * @param {number} type the collision type
427
427
  * @example
428
428
  * // set the body collision type
429
- * myEntity.body.collisionType = me.collision.types.PLAYER_OBJECT;
429
+ * body.collisionType = me.collision.types.PLAYER_OBJECT;
430
430
  */
431
431
  setCollisionType(type) {
432
432
  if (typeof type !== "undefined") {
@@ -657,7 +657,7 @@ class Body {
657
657
  * Updates the parent's position as well as computes the new body's velocity based
658
658
  * on the values of force/friction/gravity. Velocity chages are proportional to the
659
659
  * me.timer.tick value (which can be used to scale velocities). The approach to moving the
660
- * parent Entity is to compute new values of the Body.vel property then add them to
660
+ * parent renderable is to compute new values of the Body.vel property then add them to
661
661
  * the parent.pos value thus changing the postion the amount of Body.vel each time the
662
662
  * update call is made. <br>
663
663
  * Updates to Body.vel are bounded by maxVel (which defaults to viewport size if not set) <br>
@@ -1,10 +1,10 @@
1
- if (typeof window !== "undefined") {
2
- if (typeof window.console === "undefined") {
3
- window.console = {};
4
- window.console.log = function() {};
5
- window.console.assert = function() {};
6
- window.console.warn = function() {};
7
- window.console.error = function() {
1
+ if (typeof globalThis !== "undefined") {
2
+ if (typeof globalThis.console === "undefined") {
3
+ globalThis.console = {};
4
+ globalThis.console.log = function() {};
5
+ globalThis.console.assert = function() {};
6
+ globalThis.console.warn = function() {};
7
+ globalThis.console.error = function() {
8
8
  alert(Array.prototype.slice.call(arguments).join(", "));
9
9
  };
10
10
  }
@@ -0,0 +1,7 @@
1
+ // https://github.com/melonjs/melonJS/issues/1092
2
+ import "core-js/proposals/global-this";
3
+
4
+ // "built-in" polyfills
5
+ import "./console.js";
6
+ import "./performance.js";
7
+ import "./requestAnimationFrame.js";
@@ -0,0 +1,20 @@
1
+ if ("performance" in globalThis === false) {
2
+ globalThis.performance = {};
3
+ }
4
+
5
+ Date.now = (Date.now || function () { // thanks IE8
6
+ return new Date().getTime();
7
+ });
8
+
9
+ if ("now" in globalThis.performance === false) {
10
+
11
+ var nowOffset = Date.now();
12
+
13
+ if (performance.timing && performance.timing.navigationStart) {
14
+ nowOffset = performance.timing.navigationStart;
15
+ }
16
+
17
+ globalThis.performance.now = function now() {
18
+ return Date.now() - nowOffset;
19
+ };
20
+ }
@@ -6,23 +6,23 @@ var x;
6
6
 
7
7
  // standardized functions
8
8
  // https://developer.mozilla.org/fr/docs/Web/API/Window/requestAnimationFrame
9
- var requestAnimationFrame = window.requestAnimationFrame;
10
- var cancelAnimationFrame = window.cancelAnimationFrame;
9
+ var requestAnimationFrame = globalThis.requestAnimationFrame;
10
+ var cancelAnimationFrame = globalThis.cancelAnimationFrame;
11
11
 
12
12
  // get prefixed rAF and cAF is standard one not supported
13
13
  for (x = 0; x < vendors.length && !requestAnimationFrame; ++x) {
14
- requestAnimationFrame = window[vendors[x] + "RequestAnimationFrame"];
14
+ requestAnimationFrame = globalThis[vendors[x] + "RequestAnimationFrame"];
15
15
  }
16
16
  for (x = 0; x < vendors.length && !cancelAnimationFrame; ++x) {
17
- cancelAnimationFrame = window[vendors[x] + "CancelAnimationFrame"] ||
18
- window[vendors[x] + "CancelRequestAnimationFrame"];
17
+ cancelAnimationFrame = globalThis[vendors[x] + "CancelAnimationFrame"] ||
18
+ globalThis[vendors[x] + "CancelRequestAnimationFrame"];
19
19
  }
20
20
 
21
21
  if (!requestAnimationFrame || !cancelAnimationFrame) {
22
22
  requestAnimationFrame = function (callback) {
23
- var currTime = window.performance.now();
23
+ var currTime = globalThis.performance.now();
24
24
  var timeToCall = Math.max(0, (1000 / timer.maxfps) - (currTime - lastTime));
25
- var id = window.setTimeout(function () {
25
+ var id = globalThis.setTimeout(function () {
26
26
  callback(currTime + timeToCall);
27
27
  }, timeToCall);
28
28
  lastTime = currTime + timeToCall;
@@ -30,10 +30,10 @@ if (!requestAnimationFrame || !cancelAnimationFrame) {
30
30
  };
31
31
 
32
32
  cancelAnimationFrame = function (id) {
33
- window.clearTimeout(id);
33
+ globalThis.clearTimeout(id);
34
34
  };
35
35
 
36
36
  // put back in global namespace
37
- window.requestAnimationFrame = requestAnimationFrame;
38
- window.cancelAnimationFrame = cancelAnimationFrame;
37
+ globalThis.requestAnimationFrame = requestAnimationFrame;
38
+ globalThis.cancelAnimationFrame = cancelAnimationFrame;
39
39
  }
@@ -1,4 +1,4 @@
1
- import pool from "./../system/pooling.js";
1
+ import * as pool from "./../system/pooling.js";
2
2
  import { viewport } from "./../game.js";
3
3
  import Renderable from "./renderable.js";
4
4
 
@@ -1,7 +1,7 @@
1
1
  import utils from "./../utils/utils.js";
2
2
  import * as game from "./../game.js";
3
3
  import * as event from "./../system/event.js";
4
- import pool from "./../system/pooling.js";
4
+ import * as pool from "./../system/pooling.js";
5
5
  import state from "./../state/state.js";
6
6
  import Renderable from "./renderable.js";
7
7
  import Body from "./../physics/body.js";
@@ -369,6 +369,8 @@ class Container extends Renderable {
369
369
  // swap the positions..
370
370
  this.getChildren()[index] = child2;
371
371
  this.getChildren()[index2] = child;
372
+ // mark the container as dirty
373
+ this.isDirty = true;
372
374
  }
373
375
  else {
374
376
  throw new Error(child + " Both the supplied childs must be a child of the caller " + this);
@@ -748,6 +750,8 @@ class Container extends Renderable {
748
750
  if (childIndex - 1 >= 0) {
749
751
  // note : we use an inverted loop
750
752
  this.swapChildren(child, this.getChildAt(childIndex - 1));
753
+ // mark the container as dirty
754
+ this.isDirty = true;
751
755
  }
752
756
  }
753
757
 
@@ -763,6 +767,8 @@ class Container extends Renderable {
763
767
  if (childIndex >= 0 && (childIndex + 1) < this.getChildren().length) {
764
768
  // note : we use an inverted loop
765
769
  this.swapChildren(child, this.getChildAt(childIndex + 1));
770
+ // mark the container as dirty
771
+ this.isDirty = true;
766
772
  }
767
773
  }
768
774
 
@@ -781,6 +787,8 @@ class Container extends Renderable {
781
787
  children.splice(0, 0, children.splice(childIndex, 1)[0]);
782
788
  // increment our child z value based on the previous child depth
783
789
  child.pos.z = children[1].pos.z + 1;
790
+ // mark the container as dirty
791
+ this.isDirty = true;
784
792
  }
785
793
  }
786
794
 
@@ -799,6 +807,8 @@ class Container extends Renderable {
799
807
  children.splice((children.length - 1), 0, children.splice(childIndex, 1)[0]);
800
808
  // increment our child z value based on the next child depth
801
809
  child.pos.z = children[(children.length - 2)].pos.z - 1;
810
+ // mark the container as dirty
811
+ this.isDirty = true;
802
812
  }
803
813
  }
804
814