melonjs 14.5.0 → 15.1.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 (315) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
  4. package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
  5. package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
  6. package/dist/melonjs.mjs/_virtual/howler.js +1 -1
  7. package/dist/melonjs.mjs/_virtual/index.js +7 -3
  8. package/dist/melonjs.mjs/_virtual/index2.js +1 -1
  9. package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
  10. package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
  11. package/dist/melonjs.mjs/application/application.js +27 -17
  12. package/dist/melonjs.mjs/application/header.js +6 -5
  13. package/dist/melonjs.mjs/application/resize.js +20 -20
  14. package/dist/melonjs.mjs/application/settings.js +1 -1
  15. package/dist/melonjs.mjs/audio/audio.js +18 -20
  16. package/dist/melonjs.mjs/camera/camera2d.js +10 -10
  17. package/dist/melonjs.mjs/const.js +1 -1
  18. package/dist/melonjs.mjs/entity/entity.js +4 -4
  19. package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
  20. package/dist/melonjs.mjs/geometries/line.js +9 -9
  21. package/dist/melonjs.mjs/geometries/path2d.js +56 -56
  22. package/dist/melonjs.mjs/geometries/point.js +2 -2
  23. package/dist/melonjs.mjs/geometries/poly.js +29 -29
  24. package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
  25. package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
  26. package/dist/melonjs.mjs/index.js +8 -6
  27. package/dist/melonjs.mjs/input/gamepad.js +30 -30
  28. package/dist/melonjs.mjs/input/input.js +2 -2
  29. package/dist/melonjs.mjs/input/keyboard.js +15 -15
  30. package/dist/melonjs.mjs/input/pointer.js +2 -2
  31. package/dist/melonjs.mjs/input/pointerevent.js +59 -59
  32. package/dist/melonjs.mjs/lang/console.js +3 -3
  33. package/dist/melonjs.mjs/lang/deprecated.js +2 -2
  34. package/dist/melonjs.mjs/level/level.js +9 -9
  35. package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
  36. package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
  37. package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
  38. package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
  39. package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
  40. package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
  41. package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
  42. package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
  43. package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
  44. package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
  45. package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
  46. package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
  47. package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
  48. package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
  49. package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
  50. package/dist/melonjs.mjs/loader/cache.js +1 -1
  51. package/dist/melonjs.mjs/loader/loader.js +7 -7
  52. package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
  53. package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
  54. package/dist/melonjs.mjs/loader/parser.js +13 -13
  55. package/dist/melonjs.mjs/loader/settings.js +3 -3
  56. package/dist/melonjs.mjs/math/color.js +25 -24
  57. package/dist/melonjs.mjs/math/math.js +2 -2
  58. package/dist/melonjs.mjs/math/matrix2.js +22 -22
  59. package/dist/melonjs.mjs/math/matrix3.js +52 -52
  60. package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
  61. package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
  62. package/dist/melonjs.mjs/math/vector2.js +11 -11
  63. package/dist/melonjs.mjs/math/vector3.js +21 -21
  64. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
  65. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
  66. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
  67. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
  68. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
  69. package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
  70. package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
  71. package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
  72. package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
  73. package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
  74. package/dist/melonjs.mjs/particles/emitter.js +5 -5
  75. package/dist/melonjs.mjs/particles/particle.js +8 -8
  76. package/dist/melonjs.mjs/particles/settings.js +3 -3
  77. package/dist/melonjs.mjs/physics/body.js +17 -17
  78. package/dist/melonjs.mjs/physics/bounds.js +12 -12
  79. package/dist/melonjs.mjs/physics/collision.js +3 -3
  80. package/dist/melonjs.mjs/physics/detector.js +14 -14
  81. package/dist/melonjs.mjs/physics/quadtree.js +19 -19
  82. package/dist/melonjs.mjs/physics/response.js +1 -1
  83. package/dist/melonjs.mjs/physics/sat.js +60 -60
  84. package/dist/melonjs.mjs/physics/world.js +4 -4
  85. package/dist/melonjs.mjs/plugin/plugin.js +11 -11
  86. package/dist/melonjs.mjs/renderable/collectable.js +2 -2
  87. package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
  88. package/dist/melonjs.mjs/renderable/container.js +77 -59
  89. package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
  90. package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
  91. package/dist/melonjs.mjs/renderable/light2d.js +6 -6
  92. package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
  93. package/dist/melonjs.mjs/renderable/renderable.js +35 -13
  94. package/dist/melonjs.mjs/renderable/sprite.js +25 -25
  95. package/dist/melonjs.mjs/renderable/trigger.js +11 -9
  96. package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
  97. package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
  98. package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
  99. package/dist/melonjs.mjs/state/stage.js +7 -7
  100. package/dist/melonjs.mjs/state/state.js +15 -15
  101. package/dist/melonjs.mjs/system/device.js +3 -3
  102. package/dist/melonjs.mjs/system/dom.js +1 -1
  103. package/dist/melonjs.mjs/system/event.js +2 -2
  104. package/dist/melonjs.mjs/system/platform.js +1 -1
  105. package/dist/melonjs.mjs/system/pooling.js +9 -9
  106. package/dist/melonjs.mjs/system/save.js +6 -6
  107. package/dist/melonjs.mjs/system/timer.js +16 -12
  108. package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
  109. package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
  110. package/dist/melonjs.mjs/text/glyph.js +3 -3
  111. package/dist/melonjs.mjs/text/text.js +63 -92
  112. package/dist/melonjs.mjs/text/textmetrics.js +15 -15
  113. package/dist/melonjs.mjs/text/textstyle.js +4 -6
  114. package/dist/melonjs.mjs/tweens/easing.js +4 -4
  115. package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
  116. package/dist/melonjs.mjs/tweens/tween.js +11 -11
  117. package/dist/melonjs.mjs/utils/agent.js +6 -6
  118. package/dist/melonjs.mjs/utils/array.js +4 -4
  119. package/dist/melonjs.mjs/utils/file.js +1 -1
  120. package/dist/melonjs.mjs/utils/function.js +5 -5
  121. package/dist/melonjs.mjs/utils/string.js +3 -3
  122. package/dist/melonjs.mjs/utils/utils.js +16 -16
  123. package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
  124. package/dist/melonjs.mjs/video/renderer.js +70 -14
  125. package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
  126. package/dist/melonjs.mjs/video/texture/cache.js +9 -10
  127. package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
  128. package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
  129. package/dist/melonjs.mjs/video/video.js +2 -2
  130. package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
  131. package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
  132. package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
  133. package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
  134. package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
  135. package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
  136. package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
  137. package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
  138. package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
  139. package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
  140. package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
  141. package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
  142. package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
  143. package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
  144. package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
  145. package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
  146. package/dist/melonjs.module.js +25040 -25193
  147. package/dist/types/application/application.d.ts +11 -8
  148. package/dist/types/audio/audio.d.ts +3 -3
  149. package/dist/types/entity/entity.d.ts +1 -1
  150. package/dist/types/index.d.ts +7 -4
  151. package/dist/types/input/input.d.ts +1 -1
  152. package/dist/types/input/keyboard.d.ts +1 -1
  153. package/dist/types/input/pointerevent.d.ts +6 -6
  154. package/dist/types/level/level.d.ts +2 -2
  155. package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
  156. package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
  157. package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
  158. package/dist/types/loader/loader.d.ts +2 -2
  159. package/dist/types/loader/settings.d.ts +2 -2
  160. package/dist/types/particles/emitter.d.ts +1 -1
  161. package/dist/types/physics/collision.d.ts +1 -1
  162. package/dist/types/physics/detector.d.ts +1 -1
  163. package/dist/types/plugin/plugin.d.ts +2 -2
  164. package/dist/types/renderable/container.d.ts +21 -17
  165. package/dist/types/renderable/renderable.d.ts +6 -0
  166. package/dist/types/renderable/sprite.d.ts +11 -11
  167. package/dist/types/renderable/trigger.d.ts +1 -1
  168. package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
  169. package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
  170. package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
  171. package/dist/types/state/stage.d.ts +1 -1
  172. package/dist/types/system/device.d.ts +1 -1
  173. package/dist/types/system/pooling.d.ts +3 -3
  174. package/dist/types/system/timer.d.ts +5 -5
  175. package/dist/types/text/bitmaptext.d.ts +1 -1
  176. package/dist/types/text/text.d.ts +7 -21
  177. package/dist/types/text/textstyle.d.ts +1 -1
  178. package/dist/types/utils/array.d.ts +2 -2
  179. package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
  180. package/dist/types/video/renderer.d.ts +48 -4
  181. package/dist/types/video/texture/atlas.d.ts +3 -3
  182. package/dist/types/video/texture/canvas_texture.d.ts +40 -0
  183. package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
  184. package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
  185. package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
  186. package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
  187. package/dist/types/video/webgl/glshader.d.ts +1 -1
  188. package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
  189. package/package.json +16 -17
  190. package/src/application/application.js +26 -16
  191. package/src/application/header.js +5 -4
  192. package/src/application/resize.js +19 -19
  193. package/src/audio/audio.js +17 -19
  194. package/src/camera/camera2d.js +9 -9
  195. package/src/entity/entity.js +3 -3
  196. package/src/geometries/ellipse.js +5 -5
  197. package/src/geometries/line.js +8 -8
  198. package/src/geometries/path2d.js +55 -55
  199. package/src/geometries/point.js +1 -1
  200. package/src/geometries/poly.js +28 -28
  201. package/src/geometries/rectangle.js +7 -7
  202. package/src/geometries/roundrect.js +5 -5
  203. package/src/index.js +9 -4
  204. package/src/input/gamepad.js +29 -29
  205. package/src/input/input.js +1 -1
  206. package/src/input/keyboard.js +14 -14
  207. package/src/input/pointer.js +1 -1
  208. package/src/input/pointerevent.js +52 -52
  209. package/src/lang/console.js +2 -2
  210. package/src/lang/deprecated.js +1 -1
  211. package/src/level/level.js +8 -8
  212. package/src/level/tiled/TMXGroup.js +2 -2
  213. package/src/level/tiled/TMXLayer.js +30 -30
  214. package/src/level/tiled/TMXObject.js +7 -7
  215. package/src/level/tiled/TMXTile.js +7 -7
  216. package/src/level/tiled/TMXTileMap.js +18 -18
  217. package/src/level/tiled/TMXTileset.js +14 -14
  218. package/src/level/tiled/TMXTilesetGroup.js +2 -2
  219. package/src/level/tiled/TMXUtils.js +45 -40
  220. package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
  221. package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
  222. package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
  223. package/src/level/tiled/renderer/TMXRenderer.js +1 -1
  224. package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
  225. package/src/loader/loader.js +6 -6
  226. package/src/loader/loadingscreen.js +1 -1
  227. package/src/loader/parser.js +12 -12
  228. package/src/loader/settings.js +2 -2
  229. package/src/math/color.js +24 -23
  230. package/src/math/math.js +1 -1
  231. package/src/math/matrix2.js +21 -21
  232. package/src/math/matrix3.js +51 -51
  233. package/src/math/observable_vector2.js +11 -11
  234. package/src/math/observable_vector3.js +21 -21
  235. package/src/math/vector2.js +10 -10
  236. package/src/math/vector3.js +20 -20
  237. package/src/particles/emitter.js +4 -4
  238. package/src/particles/particle.js +7 -7
  239. package/src/particles/settings.js +2 -2
  240. package/src/physics/body.js +16 -16
  241. package/src/physics/bounds.js +11 -11
  242. package/src/physics/collision.js +2 -2
  243. package/src/physics/detector.js +13 -13
  244. package/src/physics/quadtree.js +18 -18
  245. package/src/physics/sat.js +59 -59
  246. package/src/physics/world.js +3 -3
  247. package/src/plugin/plugin.js +8 -8
  248. package/src/polyfill/index.js +0 -2
  249. package/src/renderable/collectable.js +1 -1
  250. package/src/renderable/container.js +76 -58
  251. package/src/renderable/dragndrop.js +4 -4
  252. package/src/renderable/imagelayer.js +6 -5
  253. package/src/renderable/light2d.js +5 -5
  254. package/src/renderable/nineslicesprite.js +11 -11
  255. package/src/renderable/renderable.js +34 -12
  256. package/src/renderable/sprite.js +24 -24
  257. package/src/renderable/trigger.js +10 -8
  258. package/src/renderable/ui/uibaseelement.js +96 -26
  259. package/src/renderable/ui/uispriteelement.js +24 -24
  260. package/src/renderable/ui/uitextbutton.js +85 -67
  261. package/src/state/stage.js +6 -6
  262. package/src/state/state.js +14 -14
  263. package/src/system/device.js +2 -2
  264. package/src/system/event.js +1 -1
  265. package/src/system/pooling.js +8 -8
  266. package/src/system/save.js +5 -5
  267. package/src/system/timer.js +15 -11
  268. package/src/text/bitmaptext.js +19 -19
  269. package/src/text/bitmaptextdata.js +21 -21
  270. package/src/text/glyph.js +2 -2
  271. package/src/text/text.js +62 -91
  272. package/src/text/textmetrics.js +14 -14
  273. package/src/text/textstyle.js +3 -5
  274. package/src/tweens/easing.js +3 -3
  275. package/src/tweens/interpolation.js +7 -7
  276. package/src/tweens/tween.js +10 -10
  277. package/src/utils/agent.js +5 -5
  278. package/src/utils/array.js +3 -3
  279. package/src/utils/function.js +4 -4
  280. package/src/utils/string.js +2 -2
  281. package/src/utils/utils.js +15 -15
  282. package/src/video/canvas/canvas_renderer.js +39 -117
  283. package/src/video/renderer.js +68 -12
  284. package/src/video/texture/atlas.js +38 -44
  285. package/src/video/texture/cache.js +6 -6
  286. package/src/video/texture/canvas_texture.js +62 -2
  287. package/src/video/video.js +1 -1
  288. package/src/video/webgl/buffer/vertex.js +22 -18
  289. package/src/video/webgl/compositors/compositor.js +79 -80
  290. package/src/video/webgl/compositors/primitive_compositor.js +68 -0
  291. package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
  292. package/src/video/webgl/glshader.js +6 -6
  293. package/src/video/webgl/shaders/primitive.vert +2 -5
  294. package/src/video/webgl/shaders/quad.vert +3 -1
  295. package/src/video/webgl/utils/attributes.js +1 -1
  296. package/src/video/webgl/utils/program.js +6 -6
  297. package/src/video/webgl/utils/uniforms.js +3 -3
  298. package/src/video/webgl/webgl_renderer.js +186 -179
  299. package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
  300. package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
  301. package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
  302. package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
  303. package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
  304. package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
  305. package/dist/melonjs.mjs/_virtual/shared.js +0 -10
  306. package/dist/melonjs.mjs/game.js +0 -29
  307. package/dist/melonjs.mjs/polyfill/console.js +0 -18
  308. package/dist/melonjs.mjs/polyfill/performance.js +0 -27
  309. package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
  310. package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
  311. package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
  312. package/dist/melonjs.mjs/video/utils/resize.js +0 -116
  313. package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
  314. package/src/polyfill/performance.js +0 -20
  315. package/src/polyfill/requestAnimationFrame.js +0 -39
@@ -59,12 +59,15 @@ import * as event from "./../../system/event.js";
59
59
  this.isContextValid = true;
60
60
  event.emit(event.ONCONTEXT_RESTORED, this);
61
61
  }, false );
62
+
63
+ // reset the renderer on game reset
64
+ event.on(event.GAME_RESET, () => {
65
+ this.reset();
66
+ });
62
67
  }
63
68
 
64
69
  /**
65
70
  * Reset context state
66
- * @name reset
67
- * @memberof CanvasRenderer
68
71
  */
69
72
  reset() {
70
73
  super.reset();
@@ -73,8 +76,6 @@ import * as event from "./../../system/event.js";
73
76
 
74
77
  /**
75
78
  * Reset the canvas transform to identity
76
- * @name resetTransform
77
- * @memberof CanvasRenderer
78
79
  */
79
80
  resetTransform() {
80
81
  this.getContext().setTransform(1, 0, 0, 1, 0, 0);
@@ -91,9 +92,7 @@ import * as event from "./../../system/event.js";
91
92
  * <img src="images/lighter-blendmode.png" width="510"/> <br>
92
93
  * - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
93
94
  * <img src="images/screen-blendmode.png" width="510"/> <br>
94
- * @name setBlendMode
95
95
  * @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
96
- * @memberof CanvasRenderer
97
96
  * @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter, "additive", "screen"
98
97
  * @param {CanvasRenderingContext2D} [context]
99
98
  */
@@ -123,27 +122,23 @@ import * as event from "./../../system/event.js";
123
122
 
124
123
  /**
125
124
  * prepare the framebuffer for drawing a new frame
126
- * @name clear
127
- * @memberof CanvasRenderer
128
125
  */
129
126
  clear() {
130
127
  if (this.settings.transparent === false) {
131
- var canvas = this.getCanvas();
132
- var context = this.getContext();
128
+ let canvas = this.getCanvas();
129
+ let context = this.getContext();
133
130
  context.clearRect(0, 0, canvas.width, canvas.height);
134
131
  }
135
132
  }
136
133
 
137
134
  /**
138
135
  * Clears the main framebuffer with the given color
139
- * @name clearColor
140
- * @memberof CanvasRenderer
141
136
  * @param {Color|string} [color="#000000"] - CSS color.
142
137
  * @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
143
138
  */
144
139
  clearColor(color = "#000000", opaque = false) {
145
- var canvas = this.getCanvas();
146
- var context = this.getContext();
140
+ let canvas = this.getCanvas();
141
+ let context = this.getContext();
147
142
 
148
143
  this.save();
149
144
  this.resetTransform();
@@ -156,8 +151,6 @@ import * as event from "./../../system/event.js";
156
151
 
157
152
  /**
158
153
  * Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
159
- * @name clearRect
160
- * @memberof CanvasRenderer
161
154
  * @param {number} x - x axis of the coordinate for the rectangle starting point.
162
155
  * @param {number} y - y axis of the coordinate for the rectangle starting point.
163
156
  * @param {number} width - The rectangle's width.
@@ -169,17 +162,15 @@ import * as event from "./../../system/event.js";
169
162
 
170
163
  /**
171
164
  * Create a pattern with the specified repetition
172
- * @name createPattern
173
- * @memberof CanvasRenderer
174
- * @param {Image} image - Source image
165
+ * @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
175
166
  * @param {string} repeat - Define how the pattern should be repeated
176
167
  * @returns {CanvasPattern}
177
168
  * @see ImageLayer#repeat
178
169
  * @example
179
- * var tileable = renderer.createPattern(image, "repeat");
180
- * var horizontal = renderer.createPattern(image, "repeat-x");
181
- * var vertical = renderer.createPattern(image, "repeat-y");
182
- * var basic = renderer.createPattern(image, "no-repeat");
170
+ * let tileable = renderer.createPattern(image, "repeat");
171
+ * let horizontal = renderer.createPattern(image, "repeat-x");
172
+ * let vertical = renderer.createPattern(image, "repeat-y");
173
+ * let basic = renderer.createPattern(image, "no-repeat");
183
174
  */
184
175
  createPattern(image, repeat) {
185
176
  return this.getContext().createPattern(image, repeat);
@@ -187,9 +178,7 @@ import * as event from "./../../system/event.js";
187
178
 
188
179
  /**
189
180
  * Draw an image onto the main using the canvas api
190
- * @name drawImage
191
- * @memberof CanvasRenderer
192
- * @param {Image} image - An element to draw into the context. The specification permits any canvas image source (CanvasImageSource), specifically, a CSSImageValue, an HTMLImageElement, an SVGImageElement, an HTMLVideoElement, an HTMLCanvasElement, an ImageBitmap, or an OffscreenCanvas.
181
+ * @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
193
182
  * @param {number} sx - The X coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
194
183
  * @param {number} sy - The Y coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context.
195
184
  * @param {number} sw - The width of the sub-rectangle of the source image to draw into the destination context. If not specified, the entire rectangle from the coordinates specified by sx and sy to the bottom-right corner of the image is used.
@@ -211,7 +200,7 @@ import * as event from "./../../system/event.js";
211
200
  // Fast path: don't draw fully transparent
212
201
  return;
213
202
  }
214
- var context = this.getContext();
203
+ let context = this.getContext();
215
204
 
216
205
  if (typeof sw === "undefined") {
217
206
  sw = dw = image.width;
@@ -239,8 +228,8 @@ import * as event from "./../../system/event.js";
239
228
  }
240
229
 
241
230
  // apply a tint if required
242
- var source = image;
243
- var tint = this.currentTint.toArray();
231
+ let source = image;
232
+ let tint = this.currentTint.toArray();
244
233
  if (tint[0] !== 1.0 || tint[1] !== 1.0 || tint[2] !== 1.0) {
245
234
  // get a tinted version of this image from the texture cache
246
235
  source = this.cache.tint(image, this.currentTint.toRGB());
@@ -250,8 +239,6 @@ import * as event from "./../../system/event.js";
250
239
 
251
240
  /**
252
241
  * Draw a pattern within the given rectangle.
253
- * @name drawPattern
254
- * @memberof CanvasRenderer
255
242
  * @param {CanvasPattern} pattern - Pattern object
256
243
  * @param {number} x
257
244
  * @param {number} y
@@ -264,8 +251,8 @@ import * as event from "./../../system/event.js";
264
251
  // Fast path: don't draw fully transparent
265
252
  return;
266
253
  }
267
- var context = this.getContext();
268
- var fillStyle = context.fillStyle;
254
+ let context = this.getContext();
255
+ let fillStyle = context.fillStyle;
269
256
  context.fillStyle = pattern;
270
257
  context.fillRect(x, y, width, height);
271
258
  context.fillStyle = fillStyle;
@@ -273,8 +260,6 @@ import * as event from "./../../system/event.js";
273
260
 
274
261
  /**
275
262
  * Stroke an arc at the specified coordinates with given radius, start and end points
276
- * @name strokeArc
277
- * @memberof CanvasRenderer
278
263
  * @param {number} x - arc center point x-axis
279
264
  * @param {number} y - arc center point y-axis
280
265
  * @param {number} radius
@@ -288,7 +273,7 @@ import * as event from "./../../system/event.js";
288
273
  // Fast path: don't draw fully transparent
289
274
  return;
290
275
  }
291
- var context = this.getContext();
276
+ let context = this.getContext();
292
277
 
293
278
  context.translate(x, y);
294
279
  context.beginPath();
@@ -299,8 +284,6 @@ import * as event from "./../../system/event.js";
299
284
 
300
285
  /**
301
286
  * Fill an arc at the specified coordinates with given radius, start and end points
302
- * @name fillArc
303
- * @memberof CanvasRenderer
304
287
  * @param {number} x - arc center point x-axis
305
288
  * @param {number} y - arc center point y-axis
306
289
  * @param {number} radius
@@ -314,8 +297,6 @@ import * as event from "./../../system/event.js";
314
297
 
315
298
  /**
316
299
  * Stroke an ellipse at the specified coordinates with given radius
317
- * @name strokeEllipse
318
- * @memberof CanvasRenderer
319
300
  * @param {number} x - ellipse center point x-axis
320
301
  * @param {number} y - ellipse center point y-axis
321
302
  * @param {number} w - horizontal radius of the ellipse
@@ -327,16 +308,16 @@ import * as event from "./../../system/event.js";
327
308
  // Fast path: don't draw fully transparent
328
309
  return;
329
310
  }
330
- var context = this.getContext();
311
+ let context = this.getContext();
331
312
 
332
- var hw = w,
313
+ let hw = w,
333
314
  hh = h,
334
315
  lx = x - hw,
335
316
  rx = x + hw,
336
317
  ty = y - hh,
337
318
  by = y + hh;
338
319
 
339
- var xmagic = hw * 0.551784,
320
+ let xmagic = hw * 0.551784,
340
321
  ymagic = hh * 0.551784,
341
322
  xmin = x - xmagic,
342
323
  xmax = x + xmagic,
@@ -355,8 +336,6 @@ import * as event from "./../../system/event.js";
355
336
 
356
337
  /**
357
338
  * Fill an ellipse at the specified coordinates with given radius
358
- * @name fillEllipse
359
- * @memberof CanvasRenderer
360
339
  * @param {number} x - ellipse center point x-axis
361
340
  * @param {number} y - ellipse center point y-axis
362
341
  * @param {number} w - horizontal radius of the ellipse
@@ -368,8 +347,6 @@ import * as event from "./../../system/event.js";
368
347
 
369
348
  /**
370
349
  * Stroke a line of the given two points
371
- * @name strokeLine
372
- * @memberof CanvasRenderer
373
350
  * @param {number} startX - the start x coordinate
374
351
  * @param {number} startY - the start y coordinate
375
352
  * @param {number} endX - the end x coordinate
@@ -381,7 +358,7 @@ import * as event from "./../../system/event.js";
381
358
  return;
382
359
  }
383
360
 
384
- var context = this.getContext();
361
+ let context = this.getContext();
385
362
 
386
363
  context.beginPath();
387
364
  context.moveTo(startX, startY);
@@ -391,8 +368,6 @@ import * as event from "./../../system/event.js";
391
368
 
392
369
  /**
393
370
  * Fill a line of the given two points
394
- * @name fillLine
395
- * @memberof CanvasRenderer
396
371
  * @param {number} startX - the start x coordinate
397
372
  * @param {number} startY - the start y coordinate
398
373
  * @param {number} endX - the end x coordinate
@@ -404,8 +379,6 @@ import * as event from "./../../system/event.js";
404
379
 
405
380
  /**
406
381
  * Stroke the given me.Polygon on the screen
407
- * @name strokePolygon
408
- * @memberof CanvasRenderer
409
382
  * @param {Polygon} poly - the shape to draw
410
383
  * @param {boolean} [fill=false] - also fill the shape with the current color if true
411
384
  */
@@ -414,13 +387,13 @@ import * as event from "./../../system/event.js";
414
387
  // Fast path: don't draw fully transparent
415
388
  return;
416
389
  }
417
- var context = this.getContext();
390
+ let context = this.getContext();
418
391
 
419
392
  this.translate(poly.pos.x, poly.pos.y);
420
393
  context.beginPath();
421
394
  context.moveTo(poly.points[0].x, poly.points[0].y);
422
- var point;
423
- for (var i = 1; i < poly.points.length; i++) {
395
+ let point;
396
+ for (let i = 1; i < poly.points.length; i++) {
424
397
  point = poly.points[i];
425
398
  context.lineTo(point.x, point.y);
426
399
  }
@@ -432,8 +405,6 @@ import * as event from "./../../system/event.js";
432
405
 
433
406
  /**
434
407
  * Fill the given me.Polygon on the screen
435
- * @name fillPolygon
436
- * @memberof CanvasRenderer
437
408
  * @param {Polygon} poly - the shape to draw
438
409
  */
439
410
  fillPolygon(poly) {
@@ -442,8 +413,6 @@ import * as event from "./../../system/event.js";
442
413
 
443
414
  /**
444
415
  * Stroke a rectangle at the specified coordinates
445
- * @name strokeRect
446
- * @memberof CanvasRenderer
447
416
  * @param {number} x
448
417
  * @param {number} y
449
418
  * @param {number} width
@@ -455,15 +424,13 @@ import * as event from "./../../system/event.js";
455
424
  // Fast path: don't draw fully transparent
456
425
  return;
457
426
  }
458
- var context = this.getContext();
427
+ let context = this.getContext();
459
428
 
460
429
  context[fill === true ? "fillRect" : "strokeRect"](x, y, width, height);
461
430
  }
462
431
 
463
432
  /**
464
433
  * Draw a filled rectangle at the specified coordinates
465
- * @name fillRect
466
- * @memberof CanvasRenderer
467
434
  * @param {number} x
468
435
  * @param {number} y
469
436
  * @param {number} width
@@ -475,8 +442,6 @@ import * as event from "./../../system/event.js";
475
442
 
476
443
  /**
477
444
  * Stroke a rounded rectangle at the specified coordinates
478
- * @name strokeRoundRect
479
- * @memberof CanvasRenderer
480
445
  * @param {number} x
481
446
  * @param {number} y
482
447
  * @param {number} width
@@ -489,7 +454,7 @@ import * as event from "./../../system/event.js";
489
454
  // Fast path: don't draw fully transparent
490
455
  return;
491
456
  }
492
- var context = this.getContext();
457
+ let context = this.getContext();
493
458
 
494
459
  context.beginPath();
495
460
  context.roundRect(x, y, width, height, radius);
@@ -498,8 +463,6 @@ import * as event from "./../../system/event.js";
498
463
 
499
464
  /**
500
465
  * Draw a rounded filled rectangle at the specified coordinates
501
- * @name fillRoundRect
502
- * @memberof CanvasRenderer
503
466
  * @param {number} x
504
467
  * @param {number} y
505
468
  * @param {number} width
@@ -512,8 +475,6 @@ import * as event from "./../../system/event.js";
512
475
 
513
476
  /**
514
477
  * Stroke a Point at the specified coordinates
515
- * @name strokePoint
516
- * @memberof CanvasRenderer
517
478
  * @param {number} x
518
479
  * @param {number} y
519
480
  */
@@ -523,8 +484,6 @@ import * as event from "./../../system/event.js";
523
484
 
524
485
  /**
525
486
  * Draw a a point at the specified coordinates
526
- * @name fillPoint
527
- * @memberof CanvasRenderer
528
487
  * @param {number} x
529
488
  * @param {number} y
530
489
  * @param {number} width
@@ -534,19 +493,8 @@ import * as event from "./../../system/event.js";
534
493
  this.strokePoint(x, y);
535
494
  }
536
495
 
537
- /**
538
- * return a reference to the font 2d Context
539
- * @ignore
540
- */
541
- getFontContext() {
542
- // in canvas mode we can directly use the 2d context
543
- return this.getContext();
544
- }
545
-
546
496
  /**
547
497
  * save the canvas context
548
- * @name save
549
- * @memberof CanvasRenderer
550
498
  */
551
499
  save() {
552
500
  this.getContext().save();
@@ -554,8 +502,6 @@ import * as event from "./../../system/event.js";
554
502
 
555
503
  /**
556
504
  * restores the canvas context
557
- * @name restore
558
- * @memberof CanvasRenderer
559
505
  */
560
506
  restore() {
561
507
  this.getContext().restore();
@@ -568,8 +514,6 @@ import * as event from "./../../system/event.js";
568
514
 
569
515
  /**
570
516
  * rotates the canvas context
571
- * @name rotate
572
- * @memberof CanvasRenderer
573
517
  * @param {number} angle - in radians
574
518
  */
575
519
  rotate(angle) {
@@ -578,8 +522,6 @@ import * as event from "./../../system/event.js";
578
522
 
579
523
  /**
580
524
  * scales the canvas context
581
- * @name scale
582
- * @memberof CanvasRenderer
583
525
  * @param {number} x
584
526
  * @param {number} y
585
527
  */
@@ -590,12 +532,10 @@ import * as event from "./../../system/event.js";
590
532
  /**
591
533
  * Set the current fill & stroke style color.
592
534
  * By default, or upon reset, the value is set to #000000.
593
- * @name setColor
594
- * @memberof CanvasRenderer
595
535
  * @param {Color|string} color - css color value
596
536
  */
597
537
  setColor(color) {
598
- var context = this.getContext();
538
+ let context = this.getContext();
599
539
  context.strokeStyle =
600
540
  context.fillStyle = (
601
541
  color instanceof Color ?
@@ -606,8 +546,6 @@ import * as event from "./../../system/event.js";
606
546
 
607
547
  /**
608
548
  * Set the global alpha
609
- * @name setGlobalAlpha
610
- * @memberof CanvasRenderer
611
549
  * @param {number} alpha - 0.0 to 1.0 values accepted.
612
550
  */
613
551
  setGlobalAlpha(alpha) {
@@ -616,8 +554,6 @@ import * as event from "./../../system/event.js";
616
554
 
617
555
  /**
618
556
  * Return the global alpha
619
- * @name getGlobalAlpha
620
- * @memberof CanvasRenderer
621
557
  * @returns {number} global alpha value
622
558
  */
623
559
  getGlobalAlpha() {
@@ -626,8 +562,6 @@ import * as event from "./../../system/event.js";
626
562
 
627
563
  /**
628
564
  * Set the line width on the context
629
- * @name setLineWidth
630
- * @memberof CanvasRenderer
631
565
  * @param {number} width - Line width
632
566
  */
633
567
  setLineWidth(width) {
@@ -637,8 +571,6 @@ import * as event from "./../../system/event.js";
637
571
  /**
638
572
  * Reset (overrides) the renderer transformation matrix to the
639
573
  * identity one, and then apply the given transformation matrix.
640
- * @name setTransform
641
- * @memberof CanvasRenderer
642
574
  * @param {Matrix2d} mat2d - Matrix to transform by
643
575
  */
644
576
  setTransform(mat2d) {
@@ -648,12 +580,10 @@ import * as event from "./../../system/event.js";
648
580
 
649
581
  /**
650
582
  * Multiply given matrix into the renderer tranformation matrix
651
- * @name transform
652
- * @memberof CanvasRenderer
653
583
  * @param {Matrix2d} mat2d - Matrix to transform by
654
584
  */
655
585
  transform(mat2d) {
656
- var m = mat2d.toArray(),
586
+ let m = mat2d.toArray(),
657
587
  a = m[0],
658
588
  b = m[1],
659
589
  c = m[3],
@@ -671,8 +601,6 @@ import * as event from "./../../system/event.js";
671
601
 
672
602
  /**
673
603
  * Translates the context to the given position
674
- * @name translate
675
- * @memberof CanvasRenderer
676
604
  * @param {number} x
677
605
  * @param {number} y
678
606
  */
@@ -690,22 +618,20 @@ import * as event from "./../../system/event.js";
690
618
  * You can however save the current region using the save(),
691
619
  * and restore it (with the restore() method) any time in the future.
692
620
  * (<u>this is an experimental feature !</u>)
693
- * @name clipRect
694
- * @memberof CanvasRenderer
695
621
  * @param {number} x
696
622
  * @param {number} y
697
623
  * @param {number} width
698
624
  * @param {number} height
699
625
  */
700
626
  clipRect(x, y, width, height) {
701
- var canvas = this.getCanvas();
627
+ let canvas = this.getCanvas();
702
628
  // if requested box is different from the current canvas size;
703
629
  if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
704
- var currentScissor = this.currentScissor;
630
+ let currentScissor = this.currentScissor;
705
631
  // if different from the current scissor box
706
632
  if (currentScissor[0] !== x || currentScissor[1] !== y ||
707
633
  currentScissor[2] !== width || currentScissor[3] !== height) {
708
- var context = this.getContext();
634
+ let context = this.getContext();
709
635
  context.beginPath();
710
636
  context.rect(x, y, width, height);
711
637
  context.clip();
@@ -722,13 +648,11 @@ import * as event from "./../../system/event.js";
722
648
  * A mask limits rendering elements to the shape and position of the given mask object.
723
649
  * So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
724
650
  * Mask are not preserved through renderer context save and restore.
725
- * @name setMask
726
- * @memberof CanvasRenderer
727
651
  * @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - the shape defining the mask to be applied
728
652
  * @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
729
653
  */
730
654
  setMask(mask, invert = false) {
731
- var context = this.getContext();
655
+ let context = this.getContext();
732
656
 
733
657
  if (this.maskLevel === 0) {
734
658
  // only save context on the first mask
@@ -750,7 +674,7 @@ import * as event from "./../../system/event.js";
750
674
  ty = _y - hh,
751
675
  by = _y + hh;
752
676
 
753
- var xmagic = hw * 0.551784,
677
+ let xmagic = hw * 0.551784,
754
678
  ymagic = hh * 0.551784,
755
679
  xmin = _x - xmagic,
756
680
  xmax = _x + xmagic,
@@ -765,10 +689,10 @@ import * as event from "./../../system/event.js";
765
689
  } else {
766
690
  // polygon
767
691
  const _x = mask.pos.x, _y = mask.pos.y;
768
- var point;
692
+ let point;
769
693
 
770
694
  context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
771
- for (var i = 1; i < mask.points.length; i++) {
695
+ for (let i = 1; i < mask.points.length; i++) {
772
696
  point = mask.points[i];
773
697
  context.lineTo(_x + point.x, _y + point.y);
774
698
  }
@@ -787,9 +711,7 @@ import * as event from "./../../system/event.js";
787
711
 
788
712
  /**
789
713
  * disable (remove) the rendering mask set through setMask.
790
- * @name clearMask
791
714
  * @see CanvasRenderer#setMask
792
- * @memberof CanvasRenderer
793
715
  */
794
716
  clearMask() {
795
717
  if (this.maskLevel > 0) {
@@ -29,6 +29,7 @@ import Point from "../geometries/point.js";
29
29
  * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
30
30
  * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
31
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")
32
33
  * @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
33
34
  * @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
34
35
  * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
@@ -63,6 +64,14 @@ import Point from "../geometries/point.js";
63
64
  */
64
65
  this.isContextValid = true;
65
66
 
67
+ /**
68
+ * the default method to sort object ("sorting", "z-buffer")
69
+ * @type {string}
70
+ * @default "sorting"
71
+ */
72
+ this.depthTest = "sorting";
73
+
74
+
66
75
  /**
67
76
  * The Path2D instance used by the renderer to draw primitives
68
77
  * @type {Path2D}
@@ -115,11 +124,6 @@ import Point from "../geometries/point.js";
115
124
 
116
125
  // default uvOffset
117
126
  this.uvOffset = 0;
118
-
119
- // reset the renderer on game reset
120
- event.on(event.GAME_RESET, () => {
121
- this.reset();
122
- });
123
127
  }
124
128
 
125
129
  /**
@@ -198,7 +202,7 @@ import Point from "../geometries/point.js";
198
202
  transparent = true;
199
203
  }
200
204
 
201
- var _context = canvas.getContext("2d", {
205
+ let _context = canvas.getContext("2d", {
202
206
  "alpha" : transparent
203
207
  });
204
208
 
@@ -260,7 +264,7 @@ import Point from "../geometries/point.js";
260
264
  * @param {number} height - new height of the canvas
261
265
  */
262
266
  resize(width, height) {
263
- var canvas = this.getCanvas();
267
+ let canvas = this.getCanvas();
264
268
  if (width !== canvas.width || height !== canvas.height) {
265
269
  canvas.width = width;
266
270
  canvas.height = height;
@@ -279,7 +283,7 @@ import Point from "../geometries/point.js";
279
283
  * @param {boolean} [enable=false]
280
284
  */
281
285
  setAntiAlias(context, enable) {
282
- var canvas = context.canvas;
286
+ let canvas = context.canvas;
283
287
 
284
288
  // enable/disable antialis on the given Context2d object
285
289
  setPrefixed("imageSmoothingEnabled", enable === true, context);
@@ -359,8 +363,8 @@ import Point from "../geometries/point.js";
359
363
  * @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
360
364
  */
361
365
  tint(src, color, mode) {
362
- var canvas = createCanvas(src.width, src.height, true);
363
- var context = this.getContext2d(canvas);
366
+ let canvas = createCanvas(src.width, src.height, true);
367
+ let context = this.getContext2d(canvas);
364
368
 
365
369
  context.save();
366
370
 
@@ -414,8 +418,60 @@ import Point from "../geometries/point.js";
414
418
  }
415
419
 
416
420
  /**
417
- * @ignore
421
+ * 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
426
+ * @example
427
+ * renderer.convertToBlob().then((blob) => console.log(blob));
428
+ */
429
+ toBlob(options) {
430
+ return new Promise((resolve) => {
431
+ event.once(event.GAME_AFTER_DRAW, () => {
432
+ this.canvas.toBlob((blob) => {
433
+ resolve(blob);
434
+ }, options ? options.type : undefined, options ? options.quality : undefined);
435
+ });
436
+ });
437
+ }
438
+
439
+ /**
440
+ * creates an ImageBitmap object of the last frame rendered
441
+ * (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.
446
+ * @example
447
+ * renderer.transferToImageBitmap().then((image) => console.log(image));
418
448
  */
419
- drawFont(/*bounds*/) {}
449
+ toImageBitmap(options) {
450
+ return new Promise((resolve) => {
451
+ event.once(event.GAME_AFTER_DRAW, () => {
452
+ let image = new Image();
453
+ image.src = this.canvas.toDataURL(options);
454
+ image.onload = () => {
455
+ createImageBitmap(image).then((bitmap) => resolve(bitmap));
456
+ };
457
+ });
458
+ });
459
+ }
420
460
 
461
+ /**
462
+ * 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.
467
+ * @example
468
+ * renderer.toDataURL().then((dataURL) => console.log(dataURL));
469
+ */
470
+ toDataURL(options) {
471
+ return new Promise((resolve) => {
472
+ event.once(event.GAME_AFTER_DRAW, () => {
473
+ resolve(this.canvas.toDataURL(options));
474
+ });
475
+ });
476
+ }
421
477
  }