melonjs 15.2.1 → 15.3.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 (163) hide show
  1. package/README.md +1 -1
  2. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  3. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/index.js +1 -1
  6. package/dist/melonjs.mjs/application/application.js +24 -20
  7. package/dist/melonjs.mjs/application/header.js +1 -1
  8. package/dist/melonjs.mjs/application/resize.js +10 -4
  9. package/dist/melonjs.mjs/application/settings.js +37 -1
  10. package/dist/melonjs.mjs/audio/audio.js +1 -1
  11. package/dist/melonjs.mjs/camera/camera2d.js +1 -1
  12. package/dist/melonjs.mjs/const.js +1 -1
  13. package/dist/melonjs.mjs/entity/entity.js +1 -1
  14. package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
  15. package/dist/melonjs.mjs/geometries/line.js +1 -1
  16. package/dist/melonjs.mjs/geometries/path2d.js +1 -1
  17. package/dist/melonjs.mjs/geometries/point.js +1 -1
  18. package/dist/melonjs.mjs/geometries/poly.js +1 -1
  19. package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
  20. package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
  21. package/dist/melonjs.mjs/index.js +2 -2
  22. package/dist/melonjs.mjs/input/gamepad.js +1 -1
  23. package/dist/melonjs.mjs/input/input.js +1 -1
  24. package/dist/melonjs.mjs/input/keyboard.js +1 -1
  25. package/dist/melonjs.mjs/input/pointer.js +1 -1
  26. package/dist/melonjs.mjs/input/pointerevent.js +1 -1
  27. package/dist/melonjs.mjs/lang/console.js +1 -1
  28. package/dist/melonjs.mjs/lang/deprecated.js +1 -1
  29. package/dist/melonjs.mjs/level/level.js +1 -1
  30. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
  31. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -1
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +1 -1
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +12 -19
  38. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  45. package/dist/melonjs.mjs/loader/cache.js +1 -1
  46. package/dist/melonjs.mjs/loader/loader.js +1 -1
  47. package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
  48. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  49. package/dist/melonjs.mjs/loader/parser.js +1 -1
  50. package/dist/melonjs.mjs/loader/settings.js +1 -1
  51. package/dist/melonjs.mjs/math/color.js +4 -4
  52. package/dist/melonjs.mjs/math/math.js +1 -1
  53. package/dist/melonjs.mjs/math/matrix2.js +1 -1
  54. package/dist/melonjs.mjs/math/matrix3.js +1 -1
  55. package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
  56. package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
  57. package/dist/melonjs.mjs/math/vector2.js +1 -1
  58. package/dist/melonjs.mjs/math/vector3.js +1 -1
  59. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
  60. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
  61. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  62. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
  63. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  64. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  65. package/dist/melonjs.mjs/particles/emitter.js +1 -1
  66. package/dist/melonjs.mjs/particles/particle.js +1 -1
  67. package/dist/melonjs.mjs/particles/settings.js +1 -1
  68. package/dist/melonjs.mjs/physics/body.js +1 -1
  69. package/dist/melonjs.mjs/physics/bounds.js +1 -1
  70. package/dist/melonjs.mjs/physics/collision.js +1 -1
  71. package/dist/melonjs.mjs/physics/detector.js +1 -1
  72. package/dist/melonjs.mjs/physics/quadtree.js +1 -1
  73. package/dist/melonjs.mjs/physics/response.js +1 -1
  74. package/dist/melonjs.mjs/physics/sat.js +1 -1
  75. package/dist/melonjs.mjs/physics/world.js +1 -1
  76. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  77. package/dist/melonjs.mjs/renderable/collectable.js +1 -1
  78. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  79. package/dist/melonjs.mjs/renderable/container.js +1 -1
  80. package/dist/melonjs.mjs/renderable/draggable.js +1 -1
  81. package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
  82. package/dist/melonjs.mjs/renderable/imagelayer.js +1 -1
  83. package/dist/melonjs.mjs/renderable/light2d.js +1 -1
  84. package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
  85. package/dist/melonjs.mjs/renderable/renderable.js +6 -14
  86. package/dist/melonjs.mjs/renderable/sprite.js +1 -1
  87. package/dist/melonjs.mjs/renderable/trigger.js +1 -1
  88. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
  89. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
  90. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
  91. package/dist/melonjs.mjs/state/stage.js +12 -13
  92. package/dist/melonjs.mjs/state/state.js +4 -14
  93. package/dist/melonjs.mjs/system/device.js +3 -1
  94. package/dist/melonjs.mjs/system/dom.js +1 -1
  95. package/dist/melonjs.mjs/system/event.js +24 -2
  96. package/dist/melonjs.mjs/system/platform.js +1 -1
  97. package/dist/melonjs.mjs/system/pooling.js +1 -1
  98. package/dist/melonjs.mjs/system/save.js +1 -1
  99. package/dist/melonjs.mjs/system/timer.js +1 -1
  100. package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
  101. package/dist/melonjs.mjs/text/bitmaptextdata.js +1 -1
  102. package/dist/melonjs.mjs/text/glyph.js +1 -1
  103. package/dist/melonjs.mjs/text/text.js +1 -1
  104. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  105. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  106. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  107. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  108. package/dist/melonjs.mjs/tweens/tween.js +1 -1
  109. package/dist/melonjs.mjs/utils/agent.js +1 -1
  110. package/dist/melonjs.mjs/utils/array.js +1 -1
  111. package/dist/melonjs.mjs/utils/file.js +1 -1
  112. package/dist/melonjs.mjs/utils/function.js +1 -1
  113. package/dist/melonjs.mjs/utils/string.js +1 -1
  114. package/dist/melonjs.mjs/utils/utils.js +1 -1
  115. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +2 -11
  116. package/dist/melonjs.mjs/video/renderer.js +2 -15
  117. package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
  118. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  119. package/dist/melonjs.mjs/video/texture/canvas_texture.js +1 -1
  120. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  121. package/dist/melonjs.mjs/video/video.js +2 -26
  122. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
  123. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
  124. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
  125. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +1 -1
  126. package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
  127. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  128. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  129. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  130. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  131. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  132. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  133. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +13 -16
  137. package/dist/melonjs.module.js +142 -144
  138. package/dist/types/application/application.d.ts +4 -27
  139. package/dist/types/application/settings.d.ts +64 -0
  140. package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
  141. package/dist/types/renderable/renderable.d.ts +1 -2
  142. package/dist/types/state/stage.d.ts +3 -2
  143. package/dist/types/system/device.d.ts +1 -0
  144. package/dist/types/system/event.d.ts +20 -0
  145. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
  146. package/dist/types/video/renderer.d.ts +3 -30
  147. package/dist/types/video/video.d.ts +2 -36
  148. package/dist/types/video/webgl/webgl_renderer.d.ts +1 -34
  149. package/package.json +6 -6
  150. package/src/application/application.js +22 -18
  151. package/src/application/resize.js +8 -2
  152. package/src/application/settings.js +36 -0
  153. package/src/level/tiled/TMXUtils.js +11 -18
  154. package/src/math/color.js +3 -3
  155. package/src/renderable/renderable.js +5 -13
  156. package/src/state/stage.js +11 -12
  157. package/src/state/state.js +2 -12
  158. package/src/system/device.js +2 -0
  159. package/src/system/event.js +22 -0
  160. package/src/video/canvas/canvas_renderer.js +1 -10
  161. package/src/video/renderer.js +1 -14
  162. package/src/video/video.js +4 -25
  163. package/src/video/webgl/webgl_renderer.js +12 -15
package/src/math/color.js CHANGED
@@ -336,12 +336,12 @@ let cssToRGB = new Map();
336
336
  * @returns {Color} Reference to this object for method chaining
337
337
  */
338
338
  copy(color) {
339
- if (color instanceof Color) {
339
+ if (typeof color === "string") {
340
+ return this.parseCSS(color);
341
+ } else {
340
342
  this.glArray.set(color.glArray);
341
343
  return this;
342
344
  }
343
-
344
- return this.parseCSS(color);
345
345
  }
346
346
 
347
347
  /**
@@ -4,7 +4,6 @@ import Rect from "./../geometries/rectangle.js";
4
4
  import pool from "./../system/pooling.js";
5
5
  import { releaseAllPointerEvents } from "./../input/input.js";
6
6
  import { clamp } from "./../math/math.js";
7
- import Color from "./../math/color.js";
8
7
 
9
8
  /**
10
9
  * @classdesc
@@ -258,6 +257,9 @@ import Color from "./../math/color.js";
258
257
  // viewport flag
259
258
  this._inViewport = false;
260
259
 
260
+ // renderable cache tint value used by the getter/setter
261
+ this._tint = pool.pull("Color", 255, 255, 255, 1.0);
262
+
261
263
  // ensure it's fully opaque by default
262
264
  this.setOpacity(1.0);
263
265
  }
@@ -282,21 +284,11 @@ import Color from "./../math/color.js";
282
284
  * this.tint.setColor(255, 255, 255);
283
285
  */
284
286
  get tint() {
285
- if (typeof this._tint === "undefined") {
286
- this._tint = pool.pull("Color", 255, 255, 255, 1.0);
287
- }
288
287
  return this._tint;
289
288
  }
290
289
  set tint(value) {
291
- if (typeof this._tint === "undefined") {
292
- this._tint = pool.pull("Color", 255, 255, 255, 1.0);
293
- }
294
- if (value instanceof Color) {
295
- this._tint.copy(value);
296
- } else {
297
- // string (#RGB, #ARGB, #RRGGBB, #AARRGGBB)
298
- this._tint.parseCSS(value);
299
- }
290
+ this._tint.copy(value);
291
+ this.isDirty = true;
300
292
  }
301
293
 
302
294
  /**
@@ -1,5 +1,5 @@
1
1
  import { renderer } from "./../video/video.js";
2
- import { game } from "../index.js";
2
+ import * as event from "./../system/event.js";
3
3
  import Camera2d from "./../camera/camera2d.js";
4
4
  import Color from "./../math/color.js";
5
5
 
@@ -87,7 +87,6 @@ let default_settings = {
87
87
  * @ignore
88
88
  */
89
89
  reset() {
90
-
91
90
  // add all defined cameras
92
91
  this.settings.cameras.forEach((camera) => {
93
92
  this.cameras.set(camera.name, camera);
@@ -105,7 +104,7 @@ let default_settings = {
105
104
  }
106
105
 
107
106
  // reset the game
108
- game.reset();
107
+ event.emit(event.STAGE_RESET, this);
109
108
 
110
109
  // call the onReset Function
111
110
  this.onResetEvent.apply(this, arguments);
@@ -120,8 +119,7 @@ let default_settings = {
120
119
  * @returns {boolean}
121
120
  */
122
121
  update(dt) {
123
- // update all objects (and pass the elapsed time since last frame)
124
- let isDirty = game.world.update(dt);
122
+ let isDirty = false;
125
123
 
126
124
  // update the camera/viewport
127
125
  // iterate through all cameras
@@ -146,13 +144,15 @@ let default_settings = {
146
144
  * @name draw
147
145
  * @memberof Stage
148
146
  * @ignore
149
- * @param {CanvasRenderer|WebGLRenderer} renderer - a renderer object
147
+ * @param {Renderer} renderer - the renderer object to draw with
148
+ * @param {World} world - the world object to draw
150
149
  */
151
- draw(renderer) {
150
+ draw(renderer, world) {
151
+
152
152
  // iterate through all cameras
153
153
  this.cameras.forEach((camera) => {
154
154
  // render the root container
155
- camera.draw(renderer, game.world);
155
+ camera.draw(renderer, world);
156
156
 
157
157
  // render the ambient light
158
158
  if (this.ambientLight.alpha !== 0) {
@@ -172,9 +172,9 @@ let default_settings = {
172
172
 
173
173
  // render all lights
174
174
  this.lights.forEach((light) => {
175
- light.preDraw(renderer, game.world);
176
- light.draw(renderer, game.world);
177
- light.postDraw(renderer, game.world);
175
+ light.preDraw(renderer, world);
176
+ light.draw(renderer, world);
177
+ light.postDraw(renderer, world);
178
178
  });
179
179
  });
180
180
  }
@@ -209,7 +209,6 @@ let default_settings = {
209
209
  if (typeof this.settings.onResetEvent === "function") {
210
210
  this.settings.onResetEvent.apply(this, arguments);
211
211
  }
212
-
213
212
  }
214
213
 
215
214
  /**
@@ -72,11 +72,7 @@ function _pauseRunLoop() {
72
72
  * @ignore
73
73
  */
74
74
  function _renderFrame(time) {
75
- let stage = _stages[_state].stage;
76
- // update all game objects
77
- game.update(time, stage);
78
- // render all game objects
79
- game.draw(stage);
75
+ event.emit(event.TICK, time);
80
76
  // schedule the next frame update
81
77
  if (_animFrameId !== -1) {
82
78
  _animFrameId = globalThis.requestAnimationFrame(_renderFrame);
@@ -125,9 +121,6 @@ function _switchState(state) {
125
121
  if (_onSwitchComplete) {
126
122
  _onSwitchComplete();
127
123
  }
128
-
129
- // force repaint
130
- game.repaint();
131
124
  }
132
125
  }
133
126
 
@@ -273,7 +266,7 @@ let state = {
273
266
  * default state ID for the default Stage
274
267
  * (the default stage is the one running as soon as melonJS is started)
275
268
  * @constant
276
- * @name SETTINGS
269
+ * @name DEFAULT
277
270
  * @memberof state
278
271
  */
279
272
  DEFAULT : 9,
@@ -361,9 +354,6 @@ let state = {
361
354
  // calculate the elpased time
362
355
  _pauseTime = globalThis.performance.now() - _pauseTime;
363
356
 
364
- // force repaint
365
- game.repaint();
366
-
367
357
  // publish the restart notification
368
358
  event.emit(event.STATE_RESTART, _pauseTime);
369
359
  }
@@ -45,6 +45,7 @@ function hasOffscreenCanvas() {
45
45
 
46
46
  /**
47
47
  * used by [un]watchAccelerometer()
48
+ * @ignore
48
49
  */
49
50
  function onDeviceMotion(e) {
50
51
  // Accelerometer information
@@ -55,6 +56,7 @@ function onDeviceMotion(e) {
55
56
 
56
57
  /**
57
58
  * used by [un]watchDeviceOrientation()
59
+ * @ignore
58
60
  */
59
61
  export function onDeviceRotate(e) {
60
62
  gamma = e.gamma;
@@ -30,6 +30,17 @@ export const DOM_READY = "dom_ready";
30
30
  */
31
31
  export const BOOT = "me.boot";
32
32
 
33
+ /**
34
+ * event generated when the system update the engine and the renderer by one step
35
+ * @public
36
+ * @constant
37
+ * @type {string}
38
+ * @name TICK
39
+ * @memberof event
40
+ * @see event.on
41
+ */
42
+ export const TICK = "me.tick";
43
+
33
44
  /**
34
45
  * event when the game is paused <br>
35
46
  * Data passed : none <br>
@@ -89,6 +100,17 @@ export const STATE_RESTART = "me.state.onRestart";
89
100
  */
90
101
  export const STATE_CHANGE = "me.state.onChange";
91
102
 
103
+ /**
104
+ * event for when a stage is resetted
105
+ * @public
106
+ * @constant
107
+ * @type {string}
108
+ * @name STAGE_RESET
109
+ * @memberof event
110
+ * @see event.on
111
+ */
112
+ export const STAGE_RESET = "me.stage.onReset";
113
+
92
114
  /**
93
115
  * event for when the video is initialized<br>
94
116
  * Data passed : none <br>
@@ -14,16 +14,7 @@ import * as event from "./../../system/event.js";
14
14
  */
15
15
  export default class CanvasRenderer extends Renderer {
16
16
  /**
17
- * @param {object} options - The renderer parameters
18
- * @param {number} options.width - The width of the canvas without scaling
19
- * @param {number} options.height - The height of the canvas without scaling
20
- * @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
21
- * @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing
22
- * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas (performance hit when enabled)
23
- * @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
24
- * @param {boolean} [options.textureSeamFix=true] - enable the texture seam fix when rendering Tile when antiAlias is off for the canvasRenderer
25
- * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
26
- * @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
17
+ * @param {Application.Settings} [options] - optional parameters for the renderer
27
18
  */
28
19
  constructor(options) {
29
20
  // parent constructor
@@ -20,20 +20,7 @@ import Point from "../geometries/point.js";
20
20
  */
21
21
  export default class Renderer {
22
22
  /**
23
- * @param {object} options - The renderer parameters
24
- * @param {number} options.width - The width of the canvas without scaling
25
- * @param {number} options.height - The height of the canvas without scaling
26
- * @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
27
- * @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing, use false (default) for a pixelated effect.
28
- * @param {boolean} [options.failIfMajorPerformanceCaveat=true] - If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
29
- * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
30
- * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
31
- * @param {boolean} [options.blendMode="normal"] - the default blend mode to use ("normal", "multiply")
32
- * @param {boolean} [options.depthBuffer="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
33
- * @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
34
- * @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
35
- * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
36
- * @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
23
+ * @param {Application.Settings} [options] - optional parameters for the renderer
37
24
  */
38
25
  constructor(options) {
39
26
  /**
@@ -10,6 +10,7 @@ import { throttle } from "../utils/function.js";
10
10
  /**
11
11
  * Select the HTML5 Canvas renderer
12
12
  * @memberof video
13
+ * @name CANVAS
13
14
  * @static
14
15
  */
15
16
  export { CANVAS } from "../const";
@@ -17,6 +18,7 @@ export { CANVAS } from "../const";
17
18
  /**
18
19
  * Select the WebGL renderer
19
20
  * @memberof video
21
+ * @name WEBGL
20
22
  * @static
21
23
  */
22
24
  export { WEBGL } from "../const";
@@ -24,6 +26,7 @@ export { WEBGL } from "../const";
24
26
  /**
25
27
  * Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
26
28
  * @memberof video
29
+ * @name AUTO
27
30
  * @static
28
31
  */
29
32
  export { AUTO } from "../const";
@@ -37,34 +40,10 @@ export let renderer = null;
37
40
 
38
41
  /**
39
42
  * Initialize the "video" system (create a canvas based on the given arguments, and the related renderer). <br>
40
- * melonJS support various scaling mode, that can be enabled <u>once the scale option is set to <b>`auto`</b></u> : <br>
41
- * - <i><b>`fit`</b></i> : Letterboxed; content is scaled to design aspect ratio <br>
42
- * <center><img src="images/scale-fit.png"/></center><br>
43
- * - <i><b>`fill-min`</b></i> : Canvas is resized to fit minimum design resolution; content is scaled to design aspect ratio <br>
44
- * <center><img src="images/scale-fill-min.png"/></center><br>
45
- * - <i><b>`fill-max`</b></i> : Canvas is resized to fit maximum design resolution; content is scaled to design aspect ratio <br>
46
- * <center><img src="images/scale-fill-max.png"/></center><br>
47
- * - <i><b>`flex`</b><</i> : Canvas width & height is resized to fit; content is scaled to design aspect ratio <br>
48
- * <center><img src="images/scale-flex.png"/></center><br>
49
- * - <i><b>`flex-width`</b></i> : Canvas width is resized to fit; content is scaled to design aspect ratio <br>
50
- * <center><img src="images/scale-flex-width.png"/></center><br>
51
- * - <i><b>`flex-height`</b></i> : Canvas height is resized to fit; content is scaled to design aspect ratio <br>
52
- * <center><img src="images/scale-flex-height.png"/></center><br>
53
- * - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio
54
- * <center><img src="images/scale-stretch.png"/></center><br>
55
43
  * @memberof video
56
44
  * @param {number} width - The width of the canvas viewport
57
45
  * @param {number} height - The height of the canvas viewport
58
- * @param {object} [options] - The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
59
- * @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
60
- * @param {number|Renderer} [options.renderer=video.AUTO] - renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO), or a custom renderer class
61
- * @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
62
- * @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
63
- * @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
64
- * @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
65
- * @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
66
- * @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
67
- * @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
46
+ * @param {Application.Settings} [options] - optional parameters for the renderer
68
47
  * @returns {boolean} false if initialization failed (canvas not supported)
69
48
  * @example
70
49
  * // init the video with a 640x480 canvas
@@ -17,21 +17,7 @@ import { isPowerOfTwo } from "./../../math/math.js";
17
17
  */
18
18
  export default class WebGLRenderer extends Renderer {
19
19
  /**
20
- * @param {object} options - The renderer parameters
21
- * @param {number} options.width - The width of the canvas without scaling
22
- * @param {number} options.height - The height of the canvas without scaling
23
- * @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
24
- * @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing
25
- * @param {boolean} [options.failIfMajorPerformanceCaveat=true] - If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
26
- * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
27
- * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
28
- * @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
29
- * @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
30
- * @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
31
- * @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
32
- * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
33
- * @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
34
- * @param {Compositor} [options.compositor] - A class that implements the compositor API for sprite rendering
20
+ * @param {Application.Settings} [options] - optional parameters for the renderer
35
21
  */
36
22
  constructor(options) {
37
23
  // parent contructor
@@ -202,6 +188,17 @@ import { isPowerOfTwo } from "./../../math/math.js";
202
188
  reset() {
203
189
  super.reset();
204
190
 
191
+ // clear all stacks
192
+ this._colorStack.forEach((color) => {
193
+ pool.push(color);
194
+ });
195
+ this._matrixStack.forEach((matrix) => {
196
+ pool.push(matrix);
197
+ });
198
+ this._colorStack.length = 0;
199
+ this._matrixStack.length = 0;
200
+ this._blendStack.length = 0;
201
+
205
202
  // clear gl context
206
203
  this.clear();
207
204