melonjs 15.2.1 → 15.4.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 (291) 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 +75 -23
  7. package/dist/melonjs.mjs/application/header.js +2 -2
  8. package/dist/melonjs.mjs/application/resize.js +13 -11
  9. package/dist/melonjs.mjs/application/settings.js +37 -1
  10. package/dist/melonjs.mjs/audio/audio.js +4 -6
  11. package/dist/melonjs.mjs/camera/camera2d.js +12 -14
  12. package/dist/melonjs.mjs/const.js +1 -1
  13. package/dist/melonjs.mjs/entity/entity.js +3 -4
  14. package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
  15. package/dist/melonjs.mjs/geometries/line.js +18 -25
  16. package/dist/melonjs.mjs/geometries/path2d.js +16 -13
  17. package/dist/melonjs.mjs/geometries/point.js +8 -16
  18. package/dist/melonjs.mjs/geometries/poly.js +40 -97
  19. package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
  20. package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
  21. package/dist/melonjs.mjs/index.js +6 -6
  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 +3 -3
  25. package/dist/melonjs.mjs/input/pointer.js +4 -4
  26. package/dist/melonjs.mjs/input/pointerevent.js +6 -7
  27. package/dist/melonjs.mjs/lang/console.js +1 -1
  28. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  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 +16 -33
  32. package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
  33. package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
  34. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
  35. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
  36. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
  37. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +37 -47
  38. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  39. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
  40. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
  41. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
  42. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  43. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
  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 +4 -5
  50. package/dist/melonjs.mjs/loader/settings.js +1 -1
  51. package/dist/melonjs.mjs/math/color.js +5 -5
  52. package/dist/melonjs.mjs/math/math.js +1 -1
  53. package/dist/melonjs.mjs/math/matrix2.js +5 -59
  54. package/dist/melonjs.mjs/math/matrix3.js +82 -141
  55. package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
  56. package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
  57. package/dist/melonjs.mjs/math/vector2.js +7 -91
  58. package/dist/melonjs.mjs/math/vector3.js +6 -90
  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 +2 -2
  66. package/dist/melonjs.mjs/particles/particle.js +2 -2
  67. package/dist/melonjs.mjs/particles/settings.js +1 -1
  68. package/dist/melonjs.mjs/physics/body.js +22 -20
  69. package/dist/melonjs.mjs/physics/bounds.js +27 -33
  70. package/dist/melonjs.mjs/physics/collision.js +5 -5
  71. package/dist/melonjs.mjs/physics/detector.js +10 -10
  72. package/dist/melonjs.mjs/physics/quadtree.js +5 -5
  73. package/dist/melonjs.mjs/physics/response.js +1 -1
  74. package/dist/melonjs.mjs/physics/sat.js +3 -4
  75. package/dist/melonjs.mjs/physics/world.js +6 -9
  76. package/dist/melonjs.mjs/plugin/plugin.js +3 -3
  77. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  78. package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
  79. package/dist/melonjs.mjs/renderable/container.js +25 -25
  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 +4 -4
  83. package/dist/melonjs.mjs/renderable/light2d.js +3 -3
  84. package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
  85. package/dist/melonjs.mjs/renderable/renderable.js +31 -39
  86. package/dist/melonjs.mjs/renderable/sprite.js +3 -3
  87. package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
  88. package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
  89. package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
  90. package/dist/melonjs.mjs/renderable/text/text.js +422 -0
  91. package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
  92. package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
  93. package/dist/melonjs.mjs/renderable/trigger.js +10 -10
  94. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
  95. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
  96. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
  97. package/dist/melonjs.mjs/state/stage.js +13 -14
  98. package/dist/melonjs.mjs/state/state.js +4 -51
  99. package/dist/melonjs.mjs/system/device.js +51 -10
  100. package/dist/melonjs.mjs/system/dom.js +1 -1
  101. package/dist/melonjs.mjs/system/event.js +46 -2
  102. package/dist/melonjs.mjs/system/platform.js +18 -18
  103. package/dist/melonjs.mjs/system/pooling.js +10 -10
  104. package/dist/melonjs.mjs/system/save.js +1 -1
  105. package/dist/melonjs.mjs/system/timer.js +1 -1
  106. package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
  107. package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
  108. package/dist/melonjs.mjs/text/glyph.js +1 -1
  109. package/dist/melonjs.mjs/text/text.js +1 -1
  110. package/dist/melonjs.mjs/text/textmetrics.js +1 -1
  111. package/dist/melonjs.mjs/text/textstyle.js +1 -1
  112. package/dist/melonjs.mjs/tweens/easing.js +1 -1
  113. package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
  114. package/dist/melonjs.mjs/tweens/tween.js +2 -2
  115. package/dist/melonjs.mjs/utils/agent.js +1 -1
  116. package/dist/melonjs.mjs/utils/array.js +1 -1
  117. package/dist/melonjs.mjs/utils/file.js +1 -1
  118. package/dist/melonjs.mjs/utils/function.js +2 -3
  119. package/dist/melonjs.mjs/utils/string.js +1 -1
  120. package/dist/melonjs.mjs/utils/utils.js +1 -1
  121. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +5 -18
  122. package/dist/melonjs.mjs/video/renderer.js +17 -30
  123. package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
  124. package/dist/melonjs.mjs/video/texture/cache.js +1 -1
  125. package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
  126. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  127. package/dist/melonjs.mjs/video/video.js +5 -29
  128. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
  129. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
  130. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
  131. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
  132. package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
  133. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  134. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  136. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +1 -1
  138. package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
  139. package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
  140. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  141. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +62 -67
  143. package/dist/melonjs.module.js +1272 -1713
  144. package/dist/types/application/application.d.ts +32 -31
  145. package/dist/types/application/header.d.ts +2 -2
  146. package/dist/types/application/settings.d.ts +80 -16
  147. package/dist/types/audio/audio.d.ts +4 -6
  148. package/dist/types/camera/camera2d.d.ts +13 -16
  149. package/dist/types/entity/entity.d.ts +0 -1
  150. package/dist/types/geometries/ellipse.d.ts +18 -50
  151. package/dist/types/geometries/path2d.d.ts +1 -1
  152. package/dist/types/geometries/point.d.ts +5 -13
  153. package/dist/types/geometries/poly.d.ts +26 -75
  154. package/dist/types/geometries/rectangle.d.ts +12 -58
  155. package/dist/types/geometries/roundrect.d.ts +2 -11
  156. package/dist/types/index.d.ts +3 -3
  157. package/dist/types/input/gamepad.d.ts +31 -31
  158. package/dist/types/input/keyboard.d.ts +105 -105
  159. package/dist/types/input/pointer.d.ts +21 -21
  160. package/dist/types/input/pointerevent.d.ts +6 -6
  161. package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
  162. package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
  163. package/dist/types/math/matrix2.d.ts +9 -63
  164. package/dist/types/math/matrix3.d.ts +9 -68
  165. package/dist/types/math/observable_vector2.d.ts +2 -2
  166. package/dist/types/math/observable_vector3.d.ts +2 -2
  167. package/dist/types/math/vector2.d.ts +8 -92
  168. package/dist/types/math/vector3.d.ts +8 -92
  169. package/dist/types/particles/settings.d.ts +29 -29
  170. package/dist/types/physics/body.d.ts +10 -8
  171. package/dist/types/physics/bounds.d.ts +24 -30
  172. package/dist/types/physics/collision.d.ts +12 -12
  173. package/dist/types/physics/detector.d.ts +1 -1
  174. package/dist/types/physics/world.d.ts +4 -7
  175. package/dist/types/renderable/container.d.ts +19 -19
  176. package/dist/types/renderable/imagelayer.d.ts +6 -6
  177. package/dist/types/renderable/light2d.d.ts +7 -7
  178. package/dist/types/renderable/renderable.d.ts +10 -18
  179. package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
  180. package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
  181. package/dist/types/renderable/text/glyph.d.ts +28 -0
  182. package/dist/types/renderable/text/text.d.ts +159 -0
  183. package/dist/types/renderable/text/textmetrics.d.ts +47 -0
  184. package/dist/types/renderable/text/textstyle.d.ts +5 -0
  185. package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
  186. package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
  187. package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
  188. package/dist/types/state/stage.d.ts +3 -2
  189. package/dist/types/state/state.d.ts +11 -11
  190. package/dist/types/system/device.d.ts +16 -9
  191. package/dist/types/system/event.d.ts +40 -0
  192. package/dist/types/system/platform.d.ts +17 -17
  193. package/dist/types/utils/function.d.ts +1 -2
  194. package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
  195. package/dist/types/video/renderer.d.ts +16 -43
  196. package/dist/types/video/texture/canvas_texture.d.ts +14 -14
  197. package/dist/types/video/video.d.ts +4 -38
  198. package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
  199. package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
  200. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
  201. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
  202. package/dist/types/video/webgl/utils/precision.d.ts +1 -1
  203. package/dist/types/video/webgl/webgl_renderer.d.ts +48 -84
  204. package/package.json +15 -15
  205. package/src/application/application.js +73 -21
  206. package/src/application/header.js +1 -1
  207. package/src/application/resize.js +11 -9
  208. package/src/application/settings.js +36 -0
  209. package/src/audio/audio.js +3 -5
  210. package/src/camera/camera2d.js +11 -13
  211. package/src/entity/entity.js +2 -3
  212. package/src/geometries/ellipse.js +25 -58
  213. package/src/geometries/line.js +17 -24
  214. package/src/geometries/path2d.js +15 -12
  215. package/src/geometries/point.js +7 -15
  216. package/src/geometries/poly.js +39 -96
  217. package/src/geometries/rectangle.js +36 -90
  218. package/src/geometries/roundrect.js +25 -34
  219. package/src/index.js +4 -4
  220. package/src/input/keyboard.js +2 -2
  221. package/src/input/pointer.js +3 -3
  222. package/src/input/pointerevent.js +5 -6
  223. package/src/lang/deprecated.js +1 -1
  224. package/src/level/tiled/TMXLayer.js +15 -32
  225. package/src/level/tiled/TMXObject.js +2 -3
  226. package/src/level/tiled/TMXTile.js +3 -3
  227. package/src/level/tiled/TMXTileMap.js +2 -2
  228. package/src/level/tiled/TMXTileset.js +3 -6
  229. package/src/level/tiled/TMXTilesetGroup.js +1 -1
  230. package/src/level/tiled/TMXUtils.js +36 -46
  231. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
  232. package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
  233. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
  234. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  235. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
  236. package/src/loader/parser.js +3 -4
  237. package/src/math/color.js +4 -4
  238. package/src/math/matrix2.js +4 -58
  239. package/src/math/matrix3.js +81 -140
  240. package/src/math/observable_vector2.js +6 -6
  241. package/src/math/observable_vector3.js +4 -4
  242. package/src/math/vector2.js +6 -90
  243. package/src/math/vector3.js +5 -89
  244. package/src/particles/emitter.js +1 -1
  245. package/src/particles/particle.js +1 -1
  246. package/src/physics/body.js +21 -19
  247. package/src/physics/bounds.js +26 -32
  248. package/src/physics/collision.js +4 -4
  249. package/src/physics/detector.js +9 -9
  250. package/src/physics/quadtree.js +4 -4
  251. package/src/physics/sat.js +2 -3
  252. package/src/physics/world.js +5 -8
  253. package/src/polyfill/roundrect.js +163 -163
  254. package/src/renderable/collectable.js +1 -1
  255. package/src/renderable/colorlayer.js +3 -3
  256. package/src/renderable/container.js +24 -24
  257. package/src/renderable/imagelayer.js +3 -3
  258. package/src/renderable/light2d.js +2 -2
  259. package/src/renderable/nineslicesprite.js +1 -1
  260. package/src/renderable/renderable.js +30 -38
  261. package/src/renderable/sprite.js +2 -2
  262. package/src/{text → renderable/text}/bitmaptext.js +8 -8
  263. package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
  264. package/src/{text → renderable/text}/glyph.js +1 -1
  265. package/src/{text → renderable/text}/text.js +16 -17
  266. package/src/{text → renderable/text}/textmetrics.js +2 -2
  267. package/src/renderable/trigger.js +9 -9
  268. package/src/renderable/ui/uibaseelement.js +6 -6
  269. package/src/renderable/ui/uispriteelement.js +6 -6
  270. package/src/renderable/ui/uitextbutton.js +2 -2
  271. package/src/state/stage.js +12 -13
  272. package/src/state/state.js +2 -61
  273. package/src/system/device.js +50 -9
  274. package/src/system/event.js +44 -0
  275. package/src/system/platform.js +18 -18
  276. package/src/system/pooling.js +9 -9
  277. package/src/tweens/tween.js +1 -1
  278. package/src/utils/function.js +1 -2
  279. package/src/video/canvas/canvas_renderer.js +4 -17
  280. package/src/video/renderer.js +16 -29
  281. package/src/video/texture/atlas.js +12 -12
  282. package/src/video/texture/canvas_texture.js +14 -14
  283. package/src/video/video.js +7 -28
  284. package/src/video/webgl/buffer/vertex.js +2 -2
  285. package/src/video/webgl/compositors/compositor.js +12 -13
  286. package/src/video/webgl/compositors/primitive_compositor.js +4 -4
  287. package/src/video/webgl/compositors/quad_compositor.js +1 -2
  288. package/src/video/webgl/glshader.js +1 -1
  289. package/src/video/webgl/utils/precision.js +3 -3
  290. package/src/video/webgl/webgl_renderer.js +61 -66
  291. /package/src/{text → renderable/text}/textstyle.js +0 -0
@@ -2,7 +2,6 @@ import { pauseTrack, resumeTrack } from "./../audio/audio.js";
2
2
  import * as fctUtil from "./../utils/function.js";
3
3
  import * as event from "./../system/event.js";
4
4
  import { game } from "../index.js";
5
- import * as device from "./../system/device.js";
6
5
  import Stage from "./../state/stage.js";
7
6
  import DefaultLoadingScreen from "./../loader/loadingscreen.js";
8
7
 
@@ -72,11 +71,7 @@ function _pauseRunLoop() {
72
71
  * @ignore
73
72
  */
74
73
  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);
74
+ event.emit(event.TICK, time);
80
75
  // schedule the next frame update
81
76
  if (_animFrameId !== -1) {
82
77
  _animFrameId = globalThis.requestAnimationFrame(_renderFrame);
@@ -125,9 +120,6 @@ function _switchState(state) {
125
120
  if (_onSwitchComplete) {
126
121
  _onSwitchComplete();
127
122
  }
128
-
129
- // force repaint
130
- game.repaint();
131
123
  }
132
124
  }
133
125
 
@@ -141,54 +133,6 @@ event.on(event.BOOT, () => {
141
133
  event.on(event.VIDEO_INIT, () => {
142
134
  state.change(state.DEFAULT, true);
143
135
  });
144
-
145
- if (typeof globalThis.addEventListener === "function") {
146
- // set pause/stop action on losing focus
147
- globalThis.addEventListener("blur", () => {
148
- if (device.stopOnBlur) {
149
- state.stop(true);
150
- }
151
- if (device.pauseOnBlur) {
152
- state.pause(true);
153
- }
154
- }, false);
155
- // set restart/resume action on gaining focus
156
- globalThis.addEventListener("focus", () => {
157
- if (device.stopOnBlur) {
158
- state.restart(true);
159
- }
160
- if (device.resumeOnFocus) {
161
- state.resume(true);
162
- }
163
- // force focus if autofocus is on
164
- if (device.autoFocus) {
165
- device.focus();
166
- }
167
- }, false);
168
- }
169
-
170
- if (typeof globalThis.document !== "undefined") {
171
- if (typeof globalThis.document.addEventListener === "function") {
172
- // register on the visibilitychange event if supported
173
- globalThis.document.addEventListener("visibilitychange", () => {
174
- if (globalThis.document.visibilityState === "visible") {
175
- if (device.stopOnBlur) {
176
- state.restart(true);
177
- }
178
- if (device.resumeOnFocus) {
179
- state.resume(true);
180
- }
181
- } else {
182
- if (device.stopOnBlur) {
183
- state.stop(true);
184
- }
185
- if (device.pauseOnBlur) {
186
- state.pause(true);
187
- }
188
- }
189
- }, false );
190
- }
191
- }
192
136
  });
193
137
 
194
138
  /**
@@ -273,7 +217,7 @@ let state = {
273
217
  * default state ID for the default Stage
274
218
  * (the default stage is the one running as soon as melonJS is started)
275
219
  * @constant
276
- * @name SETTINGS
220
+ * @name DEFAULT
277
221
  * @memberof state
278
222
  */
279
223
  DEFAULT : 9,
@@ -361,9 +305,6 @@ let state = {
361
305
  // calculate the elpased time
362
306
  _pauseTime = globalThis.performance.now() - _pauseTime;
363
307
 
364
- // force repaint
365
- game.repaint();
366
-
367
308
  // publish the restart notification
368
309
  event.emit(event.STATE_RESTART, _pauseTime);
369
310
  }
@@ -1,5 +1,6 @@
1
1
  import { getParent } from "./../video/video.js";
2
2
  import save from "./save.js";
3
+ import * as event from "./../system/event.js";
3
4
  import { prefixed } from "./../utils/agent.js";
4
5
  import { DOMContentLoaded } from "./dom.js";
5
6
  import * as device_platform from "./platform.js"; // export * as name1 from …; // ECMAScript® 2020
@@ -45,6 +46,7 @@ function hasOffscreenCanvas() {
45
46
 
46
47
  /**
47
48
  * used by [un]watchAccelerometer()
49
+ * @ignore
48
50
  */
49
51
  function onDeviceMotion(e) {
50
52
  // Accelerometer information
@@ -55,6 +57,7 @@ function onDeviceMotion(e) {
55
57
 
56
58
  /**
57
59
  * used by [un]watchDeviceOrientation()
60
+ * @ignore
58
61
  */
59
62
  export function onDeviceRotate(e) {
60
63
  gamma = e.gamma;
@@ -347,6 +350,8 @@ export let alpha = 0;
347
350
  * Specify whether to pause the game when losing focus
348
351
  * @name pauseOnBlur
349
352
  * @memberof device
353
+ * @deprecated since 15.4.0
354
+ * @see Application.pauseOnBlur
350
355
  * @type {boolean}
351
356
  * @public
352
357
  * @default true
@@ -357,6 +362,8 @@ export let pauseOnBlur = true;
357
362
  * Specify whether to unpause the game when gaining focus
358
363
  * @name resumeOnFocus
359
364
  * @memberof device
365
+ * @deprecated since 15.4.0
366
+ * @see Application.resumeOnFocus
360
367
  * @type {boolean}
361
368
  * @public
362
369
  * @default true
@@ -364,25 +371,27 @@ export let pauseOnBlur = true;
364
371
  export let resumeOnFocus = true;
365
372
 
366
373
  /**
367
- * Specify whether to automatically bring the window to the front
368
- * @name autoFocus
374
+ * Specify whether to stop the game when losing focus or not.
375
+ * The engine restarts on focus if this is enabled.
376
+ * @name stopOnBlur
369
377
  * @memberof device
378
+ * @deprecated since 15.4.0
379
+ * @see Application.stopOnBlur
370
380
  * @type {boolean}
371
381
  * @public
372
- * @default true
382
+ * @default false
373
383
  */
374
- export let autoFocus = true;
384
+ export let stopOnBlur = false;
375
385
 
376
386
  /**
377
- * Specify whether to stop the game when losing focus or not.
378
- * The engine restarts on focus if this is enabled.
379
- * @name stopOnBlur
387
+ * Specify whether to automatically bring the window to the front
388
+ * @name autoFocus
380
389
  * @memberof device
381
390
  * @type {boolean}
382
391
  * @public
383
- * @default false
392
+ * @default true
384
393
  */
385
- export let stopOnBlur = false;
394
+ export let autoFocus = true;
386
395
 
387
396
  /**
388
397
  * specify a function to execute when the Device is fully loaded and ready
@@ -430,6 +439,38 @@ export let stopOnBlur = false;
430
439
  * });
431
440
  */
432
441
  export function onReady(fn) {
442
+ // register on blur/focus and visibility event handlers
443
+ if (typeof globalThis.addEventListener === "function") {
444
+ // set pause/stop action on losing focus
445
+ globalThis.addEventListener("blur", () => {
446
+ event.emit(event.BLUR);
447
+ }, false);
448
+ // set restart/resume action on gaining focus
449
+ globalThis.addEventListener("focus", () => {
450
+ event.emit(event.FOCUS);
451
+ // force focus if autofocus is on
452
+ if (autoFocus === true) {
453
+ focus();
454
+ }
455
+ }, false);
456
+ }
457
+ if (typeof globalThis.document !== "undefined") {
458
+ if (typeof globalThis.document.addEventListener === "function") {
459
+ // register on the visibilitychange event if supported
460
+ globalThis.document.addEventListener("visibilitychange", () => {
461
+ if (globalThis.document.visibilityState === "visible") {
462
+ event.emit(event.FOCUS);
463
+ // force focus if autofocus is on
464
+ if (autoFocus === true) {
465
+ focus();
466
+ }
467
+ } else {
468
+ event.emit(event.BLUR);
469
+ }
470
+ }, false );
471
+ }
472
+ }
473
+ // call the supplied function
433
474
  DOMContentLoaded(fn);
434
475
  }
435
476
 
@@ -30,6 +30,39 @@ 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
+
44
+ /**
45
+ * event generated when the main browser or window is losing focus
46
+ * @public
47
+ * @constant
48
+ * @type {string}
49
+ * @name BLUR
50
+ * @memberof event
51
+ * @see event.on
52
+ */
53
+ export const BLUR = "me.blur";
54
+
55
+ /**
56
+ * event generated when the main browser or window is gaining back focus
57
+ * @public
58
+ * @constant
59
+ * @type {string}
60
+ * @name FOCUS
61
+ * @memberof event
62
+ * @see event.on
63
+ */
64
+ export const FOCUS = "me.focus";
65
+
33
66
  /**
34
67
  * event when the game is paused <br>
35
68
  * Data passed : none <br>
@@ -89,6 +122,17 @@ export const STATE_RESTART = "me.state.onRestart";
89
122
  */
90
123
  export const STATE_CHANGE = "me.state.onChange";
91
124
 
125
+ /**
126
+ * event for when a stage is resetted
127
+ * @public
128
+ * @constant
129
+ * @type {string}
130
+ * @name STAGE_RESET
131
+ * @memberof event
132
+ * @see event.on
133
+ */
134
+ export const STAGE_RESET = "me.stage.onReset";
135
+
92
136
  /**
93
137
  * event for when the video is initialized<br>
94
138
  * Data passed : none <br>
@@ -1,21 +1,21 @@
1
- /**
2
- * The device platform type
3
- * @namespace platform
4
- * @memberof device
5
- * @property {string} ua the user agent string for the current device
6
- * @property {boolean} iOS `true` if the device is an iOS platform
7
- * @property {boolean} android `true` if the device is an Android platform
8
- * @property {boolean} android2 `true` if the device is an Android 2.x platform
9
- * @property {boolean} linux `true` if the device is a Linux platform
10
- * @property {boolean} chromeOS `true` if the device is running on ChromeOS.
11
- * @property {boolean} wp `true` if the device is a Windows Phone platform
12
- * @property {boolean} BlackBerry`true` if the device is a BlackBerry platform
13
- * @property {boolean} Kindle`true` if the device is a Kindle platform
14
- * @property {boolean} ejecta `true` if running under Ejecta
15
- * @property {boolean} isWeixin `true` if running under Wechat
16
- * @property {boolean} nodeJS `true` if running under node.js
17
- * @property {boolean} isMobile `true` if a mobile device
18
- */
1
+ /**
2
+ * The device platform type
3
+ * @namespace platform
4
+ * @memberof device
5
+ * @property {string} ua the user agent string for the current device
6
+ * @property {boolean} iOS `true` if the device is an iOS platform
7
+ * @property {boolean} android `true` if the device is an Android platform
8
+ * @property {boolean} android2 `true` if the device is an Android 2.x platform
9
+ * @property {boolean} linux `true` if the device is a Linux platform
10
+ * @property {boolean} chromeOS `true` if the device is running on ChromeOS.
11
+ * @property {boolean} wp `true` if the device is a Windows Phone platform
12
+ * @property {boolean} BlackBerry`true` if the device is a BlackBerry platform
13
+ * @property {boolean} Kindle`true` if the device is a Kindle platform
14
+ * @property {boolean} ejecta `true` if running under Ejecta
15
+ * @property {boolean} isWeixin `true` if running under Wechat
16
+ * @property {boolean} nodeJS `true` if running under node.js
17
+ * @property {boolean} isMobile `true` if a mobile device
18
+ */
19
19
 
20
20
  export const ua = typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "";
21
21
  export const iOS = /iPhone|iPad|iPod/i.test(ua);
@@ -38,15 +38,15 @@ class ObjectPool {
38
38
  * me.pool.register("cherrysprite", Cherry, true);
39
39
  */
40
40
  register(className, classObj, recycling = false) {
41
- if (typeof (classObj) !== "undefined") {
42
- this.objectClass[className] = {
43
- "class" : classObj,
44
- "pool" : (recycling ? [] : undefined)
45
- };
46
- } else {
47
- throw new Error("Cannot register object '" + className + "', invalid class");
48
- }
49
- }
41
+ if (typeof (classObj) !== "undefined") {
42
+ this.objectClass[className] = {
43
+ "class" : classObj,
44
+ "pool" : (recycling ? [] : undefined)
45
+ };
46
+ } else {
47
+ throw new Error("Cannot register object '" + className + "', invalid class");
48
+ }
49
+ }
50
50
 
51
51
  /**
52
52
  * Pull a new instance of the requested object (if added into the object pool)
@@ -23,7 +23,7 @@ import { Interpolation } from "./interpolation.js";
23
23
  * author lechecacharro<br>
24
24
  * author Josh Faul / http://jocafa.com/
25
25
  */
26
- export default class Tween {
26
+ export default class Tween {
27
27
 
28
28
  /**
29
29
  * @param {object} object - object on which to apply the tween
@@ -23,8 +23,7 @@ export function defer(func, thisArg, ...args) {
23
23
  }
24
24
 
25
25
  /**
26
- * returns a function that, when invoked will only be triggered at most
27
- * once during a given window of time
26
+ * returns a function that, when invoked will only be triggered at most once during a given window of time
28
27
  * @public
29
28
  * @memberof utils.function
30
29
  * @name throttle
@@ -12,18 +12,9 @@ import * as event from "./../../system/event.js";
12
12
  * a canvas renderer object
13
13
  * @augments Renderer
14
14
  */
15
- export default class CanvasRenderer extends Renderer {
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
15
+ export default class CanvasRenderer extends Renderer {
16
+ /**
17
+ * @param {Application.Settings} [options] - optional parameters for the renderer
27
18
  */
28
19
  constructor(options) {
29
20
  // parent constructor
@@ -536,11 +527,7 @@ import * as event from "./../../system/event.js";
536
527
  setColor(color) {
537
528
  let context = this.getContext();
538
529
  context.strokeStyle =
539
- context.fillStyle = (
540
- color instanceof Color ?
541
- color.toRGBA() :
542
- color
543
- );
530
+ context.fillStyle = (color instanceof Color ? color.toRGBA() : color);
544
531
  }
545
532
 
546
533
  /**
@@ -18,22 +18,9 @@ import Point from "../geometries/point.js";
18
18
  * @classdesc
19
19
  * a base renderer object
20
20
  */
21
- export default class Renderer {
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
  /**
@@ -46,7 +33,7 @@ import Point from "../geometries/point.js";
46
33
  /**
47
34
  * the requested video size ratio
48
35
  * @public
49
- * @type {Number}
36
+ * @type {number}
50
37
  */
51
38
  this.designRatio = this.settings.width / this.settings.height;
52
39
 
@@ -203,7 +190,7 @@ import Point from "../geometries/point.js";
203
190
  }
204
191
 
205
192
  let _context = canvas.getContext("2d", {
206
- "alpha" : transparent
193
+ "alpha" : transparent
207
194
  });
208
195
 
209
196
  if (!_context.canvas) {
@@ -419,10 +406,10 @@ import Point from "../geometries/point.js";
419
406
 
420
407
  /**
421
408
  * creates a Blob object representing the last rendered frame
422
- * @param {Object} [options] - An object with the following properties:
423
- * @param {String} [options.type="image/png"] - A string indicating the image format
424
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
425
- * @return {Promise} A Promise returning a Blob object representing the last rendered frame
409
+ * @param {object} [options] - An object with the following properties:
410
+ * @param {string} [options.type="image/png"] - A string indicating the image format
411
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
412
+ * @returns {Promise} A Promise returning a Blob object representing the last rendered frame
426
413
  * @example
427
414
  * renderer.convertToBlob().then((blob) => console.log(blob));
428
415
  */
@@ -439,10 +426,10 @@ import Point from "../geometries/point.js";
439
426
  /**
440
427
  * creates an ImageBitmap object of the last frame rendered
441
428
  * (not supported by standard Canvas)
442
- * @param {Object} [options] - An object with the following properties:
443
- * @param {String} [options.type="image/png"] - A string indicating the image format
444
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
445
- * @return {Promise} A Promise returning an ImageBitmap.
429
+ * @param {object} [options] - An object with the following properties:
430
+ * @param {string} [options.type="image/png"] - A string indicating the image format
431
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
432
+ * @returns {Promise} A Promise returning an ImageBitmap.
446
433
  * @example
447
434
  * renderer.transferToImageBitmap().then((image) => console.log(image));
448
435
  */
@@ -460,10 +447,10 @@ import Point from "../geometries/point.js";
460
447
 
461
448
  /**
462
449
  * returns a data URL containing a representation of the last frame rendered
463
- * @param {Object} [options] - An object with the following properties:
464
- * @param {String} [options.type="image/png"] - A string indicating the image format
465
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
466
- * @return {Promise} A Promise returning a string containing the requested data URL.
450
+ * @param {object} [options] - An object with the following properties:
451
+ * @param {string} [options.type="image/png"] - A string indicating the image format
452
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
453
+ * @returns {Promise} A Promise returning a string containing the requested data URL.
467
454
  * @example
468
455
  * renderer.toDataURL().then((dataURL) => console.log(dataURL));
469
456
  */
@@ -10,18 +10,18 @@ import { ETA } from "./../../math/math.js";
10
10
  * @ignore
11
11
  */
12
12
  export function createAtlas(width, height, name = "default", repeat = "no-repeat") {
13
- return {
14
- "meta" : {
15
- "app" : "melonJS",
16
- "size" : { "w" : width, "h" : height },
17
- "repeat" : repeat,
18
- "image" : "default"
19
- },
20
- "frames" : [{
21
- "filename" : name,
22
- "frame" : { "x" : 0, "y" : 0, "w" : width, "h" : height }
23
- }]
24
- };
13
+ return {
14
+ "meta" : {
15
+ "app" : "melonJS",
16
+ "size" : { "w" : width, "h" : height },
17
+ "repeat" : repeat,
18
+ "image" : "default"
19
+ },
20
+ "frames" : [{
21
+ "filename" : name,
22
+ "frame" : { "x" : 0, "y" : 0, "w" : width, "h" : height }
23
+ }]
24
+ };
25
25
  }
26
26
 
27
27
  /**
@@ -62,7 +62,7 @@ class CanvasTexture {
62
62
 
63
63
  /**
64
64
  * enable/disable image smoothing (scaling interpolation)
65
- * @param {boolean} [enable=false]
65
+ * @param {boolean} [enable=false] - whether to enable or not image smoothing (scaling interpolation)
66
66
  */
67
67
  setAntiAlias(enable = false) {
68
68
  let canvas = this.canvas;
@@ -105,7 +105,7 @@ class CanvasTexture {
105
105
  * @param {number} y - The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted
106
106
  * @param {number} width - The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left
107
107
  * @param {number} height - The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up
108
- * @return {ImageData} The ImageData extracted from this CanvasTexture.
108
+ * @returns {ImageData} The ImageData extracted from this CanvasTexture.
109
109
  */
110
110
  getImageData(x, y, width, height) {
111
111
  // clamp values
@@ -119,10 +119,10 @@ class CanvasTexture {
119
119
 
120
120
  /**
121
121
  * creates a Blob object representing the image contained in this canvas texture
122
- * @param {Object} [options] - An object with the following properties:
123
- * @param {String} [options.type="image/png"] - A string indicating the image format
124
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
125
- * @return {Promise} A Promise returning a Blob object representing the image contained in this canvas texture
122
+ * @param {object} [options] - An object with the following properties:
123
+ * @param {string} [options.type="image/png"] - A string indicating the image format
124
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
125
+ * @returns {Promise} A Promise returning a Blob object representing the image contained in this canvas texture
126
126
  * @example
127
127
  * canvasTexture.convertToBlob().then((blob) => console.log(blob));
128
128
  */
@@ -140,10 +140,10 @@ class CanvasTexture {
140
140
 
141
141
  /**
142
142
  * creates an ImageBitmap object from the most recently rendered image of this canvas texture
143
- * @param {Object} [options] - An object with the following properties:
144
- * @param {String} [options.type="image/png"] - A string indicating the image format
145
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
146
- * @return {Promise} A Promise returning an ImageBitmap.
143
+ * @param {object} [options] - An object with the following properties:
144
+ * @param {string} [options.type="image/png"] - A string indicating the image format
145
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
146
+ * @returns {Promise} A Promise returning an ImageBitmap.
147
147
  * @example
148
148
  * canvasTexture.transferToImageBitmap().then((bitmap) => console.log(bitmap));
149
149
  */
@@ -164,10 +164,10 @@ class CanvasTexture {
164
164
  /**
165
165
  * returns a data URL containing a representation of the most recently rendered image of this canvas texture
166
166
  * (not supported by OffscreenCanvas)
167
- * @param {Object} [options] - An object with the following properties:
168
- * @param {String} [options.type="image/png"] - A string indicating the image format
169
- * @param {Number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
170
- * @return {Promise} A Promise returning a string containing the requested data URL.
167
+ * @param {object} [options] - An object with the following properties:
168
+ * @param {string} [options.type="image/png"] - A string indicating the image format
169
+ * @param {number} [options.quality] - A Number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.
170
+ * @returns {Promise} A Promise returning a string containing the requested data URL.
171
171
  * @example
172
172
  * renderer.toDataURL().then((dataURL) => console.log(dataURL));
173
173
  */