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
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -8,7 +8,7 @@
8
8
  import Color from '../math/color.js';
9
9
  import Matrix3d from '../math/matrix3.js';
10
10
  import { createCanvas } from './video.js';
11
- import { on, emit, GAME_RESET, CANVAS_ONRESIZE } from '../system/event.js';
11
+ import { emit, once, CANVAS_ONRESIZE, GAME_AFTER_DRAW } from '../system/event.js';
12
12
  import { platform } from '../system/device.js';
13
13
  import { setPrefixed } from '../utils/agent.js';
14
14
  import Rect from '../geometries/rectangle.js';
@@ -36,6 +36,7 @@ import Point from '../geometries/point.js';
36
36
  * @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
37
37
  * @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
38
38
  * @param {boolean} [options.blendMode="normal"] - the default blend mode to use ("normal", "multiply")
39
+ * @param {boolean} [options.depthBuffer="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
39
40
  * @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
40
41
  * @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
41
42
  * @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
@@ -70,6 +71,14 @@ import Point from '../geometries/point.js';
70
71
  */
71
72
  this.isContextValid = true;
72
73
 
74
+ /**
75
+ * the default method to sort object ("sorting", "z-buffer")
76
+ * @type {string}
77
+ * @default "sorting"
78
+ */
79
+ this.depthTest = "sorting";
80
+
81
+
73
82
  /**
74
83
  * The Path2D instance used by the renderer to draw primitives
75
84
  * @type {Path2D}
@@ -122,11 +131,6 @@ import Point from '../geometries/point.js';
122
131
 
123
132
  // default uvOffset
124
133
  this.uvOffset = 0;
125
-
126
- // reset the renderer on game reset
127
- on(GAME_RESET, () => {
128
- this.reset();
129
- });
130
134
  }
131
135
 
132
136
  /**
@@ -205,7 +209,7 @@ import Point from '../geometries/point.js';
205
209
  transparent = true;
206
210
  }
207
211
 
208
- var _context = canvas.getContext("2d", {
212
+ let _context = canvas.getContext("2d", {
209
213
  "alpha" : transparent
210
214
  });
211
215
 
@@ -267,7 +271,7 @@ import Point from '../geometries/point.js';
267
271
  * @param {number} height - new height of the canvas
268
272
  */
269
273
  resize(width, height) {
270
- var canvas = this.getCanvas();
274
+ let canvas = this.getCanvas();
271
275
  if (width !== canvas.width || height !== canvas.height) {
272
276
  canvas.width = width;
273
277
  canvas.height = height;
@@ -286,7 +290,7 @@ import Point from '../geometries/point.js';
286
290
  * @param {boolean} [enable=false]
287
291
  */
288
292
  setAntiAlias(context, enable) {
289
- var canvas = context.canvas;
293
+ let canvas = context.canvas;
290
294
 
291
295
  // enable/disable antialis on the given Context2d object
292
296
  setPrefixed("imageSmoothingEnabled", enable === true, context);
@@ -366,8 +370,8 @@ import Point from '../geometries/point.js';
366
370
  * @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
367
371
  */
368
372
  tint(src, color, mode) {
369
- var canvas = createCanvas(src.width, src.height, true);
370
- var context = this.getContext2d(canvas);
373
+ let canvas = createCanvas(src.width, src.height, true);
374
+ let context = this.getContext2d(canvas);
371
375
 
372
376
  context.save();
373
377
 
@@ -421,10 +425,62 @@ import Point from '../geometries/point.js';
421
425
  }
422
426
 
423
427
  /**
424
- * @ignore
428
+ * creates a Blob object representing the last rendered frame
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
+ * @return {Promise} A Promise returning a Blob object representing the last rendered frame
433
+ * @example
434
+ * renderer.convertToBlob().then((blob) => console.log(blob));
435
+ */
436
+ toBlob(options) {
437
+ return new Promise((resolve) => {
438
+ once(GAME_AFTER_DRAW, () => {
439
+ this.canvas.toBlob((blob) => {
440
+ resolve(blob);
441
+ }, options ? options.type : undefined, options ? options.quality : undefined);
442
+ });
443
+ });
444
+ }
445
+
446
+ /**
447
+ * creates an ImageBitmap object of the last frame rendered
448
+ * (not supported by standard Canvas)
449
+ * @param {Object} [options] - An object with the following properties:
450
+ * @param {String} [options.type="image/png"] - A string indicating the image format
451
+ * @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.
452
+ * @return {Promise} A Promise returning an ImageBitmap.
453
+ * @example
454
+ * renderer.transferToImageBitmap().then((image) => console.log(image));
425
455
  */
426
- drawFont(/*bounds*/) {}
456
+ toImageBitmap(options) {
457
+ return new Promise((resolve) => {
458
+ once(GAME_AFTER_DRAW, () => {
459
+ let image = new Image();
460
+ image.src = this.canvas.toDataURL(options);
461
+ image.onload = () => {
462
+ createImageBitmap(image).then((bitmap) => resolve(bitmap));
463
+ };
464
+ });
465
+ });
466
+ }
427
467
 
468
+ /**
469
+ * returns a data URL containing a representation of the last frame rendered
470
+ * @param {Object} [options] - An object with the following properties:
471
+ * @param {String} [options.type="image/png"] - A string indicating the image format
472
+ * @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.
473
+ * @return {Promise} A Promise returning a string containing the requested data URL.
474
+ * @example
475
+ * renderer.toDataURL().then((dataURL) => console.log(dataURL));
476
+ */
477
+ toDataURL(options) {
478
+ return new Promise((resolve) => {
479
+ once(GAME_AFTER_DRAW, () => {
480
+ resolve(this.canvas.toDataURL(options));
481
+ });
482
+ });
483
+ }
428
484
  }
429
485
 
430
486
  export { Renderer as default };
@@ -1,13 +1,11 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
6
6
  * @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
7
7
  */
8
8
  import Vector2d from '../../math/vector2.js';
9
- import WebGLRenderer from '../webgl/webgl_renderer.js';
10
- import TextureCache from './cache.js';
11
9
  import Sprite from '../../renderable/sprite.js';
12
10
  import { renderer } from '../video.js';
13
11
  import pool from '../../system/pooling.js';
@@ -95,8 +93,8 @@ class TextureAtlas {
95
93
  if (typeof (atlases) !== "undefined") {
96
94
  // normalize to array to keep the following code generic
97
95
  atlases = Array.isArray(atlases) ? atlases : [atlases];
98
- for (var i in atlases) {
99
- var atlas = atlases[i];
96
+ for (let i in atlases) {
97
+ let atlas = atlases[i];
100
98
 
101
99
  if (typeof(atlas.meta) !== "undefined") {
102
100
  // Texture Packer or Free Texture Packer
@@ -105,7 +103,7 @@ class TextureAtlas {
105
103
  // set the texture
106
104
  if (typeof(src) === "undefined") {
107
105
  // get the texture name from the atlas meta data
108
- var image = getImage(atlas.meta.image);
106
+ let image = getImage(atlas.meta.image);
109
107
  if (!image) {
110
108
  throw new Error(
111
109
  "Atlas texture '" + image + "' not found"
@@ -166,11 +164,7 @@ class TextureAtlas {
166
164
  // Add self to TextureCache if cache !== false
167
165
  if (cache !== false) {
168
166
  this.sources.forEach((source) => {
169
- if (cache instanceof TextureCache) {
170
- cache.set(source, this);
171
- } else {
172
- renderer.cache.set(source, this);
173
- }
167
+ renderer.cache.set(source, this);
174
168
  });
175
169
  }
176
170
  }
@@ -180,17 +174,17 @@ class TextureAtlas {
180
174
  * @ignore
181
175
  */
182
176
  parse(data) {
183
- var atlas = {};
177
+ let atlas = {};
184
178
 
185
179
  data.frames.forEach((frame) => {
186
180
  // fix wrongly formatted JSON (e.g. last dummy object in ShoeBox)
187
181
  if (frame.hasOwnProperty("filename")) {
188
182
  // Source coordinates
189
- var s = frame.frame;
183
+ let s = frame.frame;
190
184
 
191
- var originX, originY;
185
+ let originX, originY;
192
186
  // Pixel-based offset origin from the top-left of the source frame
193
- var hasTextureAnchorPoint = (frame.spriteSourceSize && frame.sourceSize && frame.pivot);
187
+ let hasTextureAnchorPoint = (frame.spriteSourceSize && frame.sourceSize && frame.pivot);
194
188
  if (hasTextureAnchorPoint) {
195
189
  originX = (frame.sourceSize.w * frame.pivot.x) - ((frame.trimmed) ? frame.spriteSourceSize.x : 0);
196
190
  originY = (frame.sourceSize.h * frame.pivot.y) - ((frame.trimmed) ? frame.spriteSourceSize.y : 0);
@@ -217,16 +211,16 @@ class TextureAtlas {
217
211
  * @ignore
218
212
  */
219
213
  parseFromSpriteSheet(data) {
220
- var atlas = {};
221
- var image = data.image;
222
- var spacing = data.spacing || 0;
223
- var margin = data.margin || 0;
214
+ let atlas = {};
215
+ let image = data.image;
216
+ let spacing = data.spacing || 0;
217
+ let margin = data.margin || 0;
224
218
 
225
- var width = image.width;
226
- var height = image.height;
219
+ let width = image.width;
220
+ let height = image.height;
227
221
 
228
222
  // calculate the sprite count (line, col)
229
- var spritecount = pool.pull("Vector2d",
223
+ let spritecount = pool.pull("Vector2d",
230
224
  ~~((width - margin + spacing) / (data.framewidth + spacing)),
231
225
  ~~((height - margin + spacing) / (data.frameheight + spacing))
232
226
  );
@@ -234,8 +228,8 @@ class TextureAtlas {
234
228
  // verifying the texture size
235
229
  if ((width % (data.framewidth + spacing)) !== 0 ||
236
230
  (height % (data.frameheight + spacing)) !== 0) {
237
- var computed_width = spritecount.x * (data.framewidth + spacing);
238
- var computed_height = spritecount.y * (data.frameheight + spacing);
231
+ let computed_width = spritecount.x * (data.framewidth + spacing);
232
+ let computed_height = spritecount.y * (data.frameheight + spacing);
239
233
  if (computed_width - width !== spacing && computed_height - height !== spacing) {
240
234
  // "truncate size" if delta is different from the spacing size
241
235
  width = computed_width;
@@ -251,8 +245,8 @@ class TextureAtlas {
251
245
  }
252
246
 
253
247
  // build the local atlas
254
- for (var frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
255
- var name = "" + frame;
248
+ for (let frame = 0, count = spritecount.x * spritecount.y; frame < count; frame++) {
249
+ let name = "" + frame;
256
250
  atlas[name] = {
257
251
  name : name,
258
252
  texture : "default", // the source texture
@@ -323,10 +317,10 @@ class TextureAtlas {
323
317
  console.warn("Adding texture region", name, "for texture", this);
324
318
  }
325
319
 
326
- var source = this.getTexture();
327
- var atlas = this.getAtlas();
328
- var dw = source.width;
329
- var dh = source.height;
320
+ let source = this.getTexture();
321
+ let atlas = this.getAtlas();
322
+ let dw = source.width;
323
+ let dh = source.height;
330
324
 
331
325
  atlas[name] = {
332
326
  name : name,
@@ -348,7 +342,7 @@ class TextureAtlas {
348
342
  * @returns {object}
349
343
  */
350
344
  getRegion(name, atlas) {
351
- var region;
345
+ let region;
352
346
  if (typeof atlas === "string") {
353
347
  region = this.getAtlas(atlas)[name];
354
348
  } else {
@@ -371,11 +365,11 @@ class TextureAtlas {
371
365
  */
372
366
  getUVs(name) {
373
367
  // Get the source texture region
374
- var region = this.getRegion(name);
368
+ let region = this.getRegion(name);
375
369
 
376
370
  if (typeof(region) === "undefined") {
377
371
  // TODO: Require proper atlas regions instead of caching arbitrary region keys
378
- var keys = name.split(","),
372
+ let keys = name.split(","),
379
373
  sx = +keys[0],
380
374
  sy = +keys[1],
381
375
  sw = +keys[2],
@@ -395,11 +389,11 @@ class TextureAtlas {
395
389
  */
396
390
  addUVs(atlas, name, w, h) {
397
391
  // ignore if using the Canvas Renderer
398
- if (renderer instanceof WebGLRenderer) {
392
+ if (typeof renderer.gl !== "undefined") {
399
393
  // Source coordinates
400
- var s = atlas[name].offset;
401
- var sw = atlas[name].width;
402
- var sh = atlas[name].height;
394
+ let s = atlas[name].offset;
395
+ let sw = atlas[name].width;
396
+ let sh = atlas[name].height;
403
397
 
404
398
  atlas[name].uvs = new Float32Array([
405
399
  s.x / w, // u0 (left)
@@ -409,7 +403,7 @@ class TextureAtlas {
409
403
  ]);
410
404
  // Cache source coordinates
411
405
  // TODO: Remove this when the Batcher only accepts a region name
412
- var key = s.x + "," + s.y + "," + w + "," + h;
406
+ let key = s.x + "," + s.y + "," + w + "," + h;
413
407
  atlas[key] = atlas[name];
414
408
  }
415
409
  return atlas[name].uvs;
@@ -430,13 +424,13 @@ class TextureAtlas {
430
424
  * ...
431
425
  * ...
432
426
  * // create a new "coin" sprite
433
- * var sprite = game.texture.createSpriteFromName("coin.png");
427
+ * let sprite = game.texture.createSpriteFromName("coin.png");
434
428
  * // set the renderable position to bottom center
435
429
  * sprite.anchorPoint.set(0.5, 1.0);
436
430
  * ...
437
431
  * ...
438
432
  * // create a 9-slice sprite
439
- * var dialogPanel = game.texture.createSpriteFromName(
433
+ * let dialogPanel = game.texture.createSpriteFromName(
440
434
  * "rpg_dialo.png",
441
435
  * // width & height are mandatory for 9-slice sprites
442
436
  * { width: this.width, height: this.height },
@@ -469,7 +463,7 @@ class TextureAtlas {
469
463
  * );
470
464
  *
471
465
  * // create a new Animated Sprite
472
- * var sprite = game.texture.createAnimationFromName([
466
+ * let sprite = game.texture.createAnimationFromName([
473
467
  * "walk0001.png", "walk0002.png", "walk0003.png",
474
468
  * "walk0004.png", "walk0005.png", "walk0006.png",
475
469
  * "walk0007.png", "walk0008.png", "walk0009.png",
@@ -486,12 +480,12 @@ class TextureAtlas {
486
480
  * sprite.anchorPoint.set(0.5, 1.0);
487
481
  */
488
482
  createAnimationFromName(names, settings) {
489
- var tpAtlas = [], indices = {};
490
- var width = 0, height = 0;
491
- var region;
483
+ let tpAtlas = [], indices = {};
484
+ let width = 0, height = 0;
485
+ let region;
492
486
  // iterate through the given names
493
487
  // and create a "normalized" atlas
494
- for (var i = 0; i < names.length; ++i) {
488
+ for (let i = 0; i < names.length; ++i) {
495
489
  region = this.getRegion(names[i]);
496
490
  if (region == null) {
497
491
  // throw an error
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -9,8 +9,7 @@ import { renderer } from '../video.js';
9
9
  import { getBasename } from '../../utils/file.js';
10
10
  import { createAtlas, TextureAtlas } from './atlas.js';
11
11
  import { isPowerOfTwo } from '../../math/math.js';
12
- import '../../node_modules/@teppeis/multimaps/dist/src/index.js';
13
- import { __exports as src } from '../../_virtual/index.js';
12
+ import { ArrayMultimap } from '../../node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js';
14
13
 
15
14
  /**
16
15
  * a basic texture cache object
@@ -23,7 +22,7 @@ class TextureCache {
23
22
  */
24
23
  constructor(max_size) {
25
24
  // cache uses an array to allow for duplicated key
26
- this.cache = new src.ArrayMultimap();
25
+ this.cache = new ArrayMultimap();
27
26
  this.tinted = new Map();
28
27
  this.units = new Map();
29
28
  this.max_size = max_size || Infinity;
@@ -57,14 +56,14 @@ class TextureCache {
57
56
  * @ignore
58
57
  */
59
58
  get(image, atlas) {
60
- var entry;
59
+ let entry;
61
60
 
62
61
  if (typeof atlas === "undefined") {
63
62
  entry = this.cache.get(image)[0];
64
63
  } else {
65
64
  // manage cases where a specific atlas is specified
66
65
  this.cache.forEach((value, key) => {
67
- var _atlas = value.getAtlas()[0];
66
+ let _atlas = value.getAtlas()[0];
68
67
  if (key === image && _atlas.width === atlas.framewidth && _atlas.height === atlas.frameheight) {
69
68
  entry = value;
70
69
  }
@@ -96,7 +95,7 @@ class TextureCache {
96
95
  */
97
96
  tint(src, color) {
98
97
  // make sure the src is in the cache
99
- var image_cache = this.tinted.get(src);
98
+ let image_cache = this.tinted.get(src);
100
99
 
101
100
  if (image_cache === undefined) {
102
101
  image_cache = this.tinted.set(src, new Map());
@@ -113,12 +112,12 @@ class TextureCache {
113
112
  * @ignore
114
113
  */
115
114
  set(image, texture) {
116
- var width = image.width;
117
- var height = image.height;
115
+ let width = image.width;
116
+ let height = image.height;
118
117
 
119
118
  // warn if a non POT texture is added to the cache when using WebGL1
120
119
  if (renderer.WebGLVersion === 1 && (!isPowerOfTwo(width) || !isPowerOfTwo(height))) {
121
- var src = typeof image.src !== "undefined" ? image.src : image;
120
+ let src = typeof image.src !== "undefined" ? image.src : image;
122
121
  console.warn(
123
122
  "[Texture] " + src + " is not a POT texture " +
124
123
  "(" + width + "x" + height + ")"
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -10,7 +10,7 @@ import { setPrefixed } from '../../utils/agent.js';
10
10
  import { clamp } from '../../math/math.js';
11
11
 
12
12
  // default canvas settings
13
- var defaultAttributes = {
13
+ let defaultAttributes = {
14
14
  offscreenCanvas : false,
15
15
  willReadFrequently : false,
16
16
  antiAlias : false,
@@ -72,7 +72,7 @@ class CanvasTexture {
72
72
  * @param {boolean} [enable=false]
73
73
  */
74
74
  setAntiAlias(enable = false) {
75
- var canvas = this.canvas;
75
+ let canvas = this.canvas;
76
76
 
77
77
  // enable/disable antialias on the given Context2d object
78
78
  setPrefixed("imageSmoothingEnabled", enable, this.context);
@@ -124,6 +124,66 @@ class CanvasTexture {
124
124
  return this.context.getImageData(x, y, width, height);
125
125
  }
126
126
 
127
+ /**
128
+ * creates a Blob object representing the image contained in this canvas texture
129
+ * @param {Object} [options] - An object with the following properties:
130
+ * @param {String} [options.type="image/png"] - A string indicating the image format
131
+ * @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.
132
+ * @return {Promise} A Promise returning a Blob object representing the image contained in this canvas texture
133
+ * @example
134
+ * canvasTexture.convertToBlob().then((blob) => console.log(blob));
135
+ */
136
+ toBlob(options) {
137
+ if (typeof this.canvas.convertToBlob === "function") {
138
+ return this.canvas.convertToBlob(options);
139
+ } else {
140
+ return new Promise(function(resolve) {
141
+ this.canvas.toBlob((blob) => {
142
+ resolve(blob);
143
+ }, options ? options.type : undefined, options ? options.quality : undefined);
144
+ });
145
+ }
146
+ }
147
+
148
+ /**
149
+ * creates an ImageBitmap object from the most recently rendered image of this canvas texture
150
+ * @param {Object} [options] - An object with the following properties:
151
+ * @param {String} [options.type="image/png"] - A string indicating the image format
152
+ * @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.
153
+ * @return {Promise} A Promise returning an ImageBitmap.
154
+ * @example
155
+ * canvasTexture.transferToImageBitmap().then((bitmap) => console.log(bitmap));
156
+ */
157
+ toImageBitmap(options) {
158
+ return new Promise((resolve) => {
159
+ if (typeof this.canvas.transferToImageBitmap === "function") {
160
+ resolve(this.canvas.transferToImageBitmap());
161
+ } else {
162
+ let image = new Image();
163
+ image.src = this.canvas.toDataURL(options);
164
+ image.onload = () => {
165
+ createImageBitmap(image).then((bitmap) => resolve(bitmap));
166
+ };
167
+ }
168
+ });
169
+ }
170
+
171
+ /**
172
+ * returns a data URL containing a representation of the most recently rendered image of this canvas texture
173
+ * (not supported by OffscreenCanvas)
174
+ * @param {Object} [options] - An object with the following properties:
175
+ * @param {String} [options.type="image/png"] - A string indicating the image format
176
+ * @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.
177
+ * @return {Promise} A Promise returning a string containing the requested data URL.
178
+ * @example
179
+ * renderer.toDataURL().then((dataURL) => console.log(dataURL));
180
+ */
181
+ toDataURL(options) {
182
+ return new Promise((resolve) => {
183
+ resolve(this.canvas.toDataURL(options));
184
+ });
185
+ }
186
+
127
187
  /**
128
188
  * @ignore
129
189
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -156,7 +156,7 @@ function init(width, height, options) {
156
156
  * @returns {HTMLCanvasElement|OffscreenCanvas}
157
157
  */
158
158
  function createCanvas(width, height, returnOffscreenCanvas = false) {
159
- var _canvas;
159
+ let _canvas;
160
160
 
161
161
  if (width === 0 || height === 0) {
162
162
  throw new Error("width or height was zero, Canvas could not be initialized !");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * melonJS Game Engine - v14.5.0
2
+ * melonJS Game Engine - v15.1.0
3
3
  * http://www.melonjs.org
4
4
  * melonjs is licensed under the MIT License.
5
5
  * http://www.opensource.org/licenses/mit-license
@@ -14,18 +14,18 @@
14
14
 
15
15
  class VertexArrayBuffer {
16
16
 
17
- constructor(vertex_size, vertex_per_quad) {
17
+ constructor(vertex_size, vertex_per_obj) {
18
18
  // the size of one vertex in float
19
19
  this.vertexSize = vertex_size;
20
- // size of a quad in vertex
21
- this.quadSize = vertex_per_quad;
20
+ // size of an object in vertex
21
+ this.objSize = vertex_per_obj;
22
22
  // the maximum number of vertices the vertex array buffer can hold
23
- this.maxVertex = 256;
23
+ this.maxVertex = 256; // (note: this seems to be the sweet spot performance-wise when using batching)
24
24
  // the current number of vertices added to the vertex array buffer
25
25
  this.vertexCount = 0;
26
26
 
27
27
  // the actual vertex data buffer
28
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
28
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
29
29
  // Float32 and Uint32 view of the vertex data array buffer
30
30
  this.bufferF32 = new Float32Array(this.buffer);
31
31
  this.bufferU32 = new Uint32Array(this.buffer);
@@ -44,7 +44,7 @@
44
44
  * return true if full
45
45
  * @ignore
46
46
  */
47
- isFull(vertex = this.quadSize) {
47
+ isFull(vertex = this.objSize) {
48
48
  return (this.vertexCount + vertex >= this.maxVertex);
49
49
  }
50
50
 
@@ -52,14 +52,18 @@
52
52
  * resize the vertex buffer, retaining its original contents
53
53
  * @ignore
54
54
  */
55
- resize() {
56
- // double the vertex size
57
- this.maxVertex <<= 1;
55
+ resize(vertexCount) {
56
+
57
+ while (vertexCount > this.maxVertex) {
58
+ // double the vertex size
59
+ this.maxVertex <<= 1;
60
+ }
61
+
58
62
  // save a reference to the previous data
59
- var data = this.bufferF32;
63
+ let data = this.bufferF32;
60
64
 
61
65
  // recreate ArrayBuffer and views
62
- this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.quadSize);
66
+ this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
63
67
  this.bufferF32 = new Float32Array(this.buffer);
64
68
  this.bufferU32 = new Uint32Array(this.buffer);
65
69
 
@@ -74,22 +78,22 @@
74
78
  * @ignore
75
79
  */
76
80
  push(x, y, u, v, tint) {
77
- var offset = this.vertexCount * this.vertexSize;
81
+ let offset = this.vertexCount * this.vertexSize;
78
82
 
79
83
  if (this.vertexCount >= this.maxVertex) {
80
- this.resize();
84
+ this.resize(this.vertexCount);
81
85
  }
82
86
 
83
- this.bufferF32[offset + 0] = x;
84
- this.bufferF32[offset + 1] = y;
87
+ this.bufferF32[offset] = x;
88
+ this.bufferF32[++offset] = y;
85
89
 
86
90
  if (typeof u !== "undefined") {
87
- this.bufferF32[offset + 2] = u;
88
- this.bufferF32[offset + 3] = v;
91
+ this.bufferF32[++offset] = u;
92
+ this.bufferF32[++offset] = v;
89
93
  }
90
94
 
91
95
  if (typeof tint !== "undefined") {
92
- this.bufferU32[offset + 4] = tint;
96
+ this.bufferU32[++offset] = tint;
93
97
  }
94
98
 
95
99
  this.vertexCount++;