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.
- package/LICENSE.md +1 -1
- package/README.md +6 -6
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.js +1 -1
- package/dist/melonjs.mjs/_virtual/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/earcut.js +1 -1
- package/dist/melonjs.mjs/_virtual/howler.js +1 -1
- package/dist/melonjs.mjs/_virtual/index.js +7 -3
- package/dist/melonjs.mjs/_virtual/index2.js +1 -1
- package/dist/melonjs.mjs/_virtual/multimap.js +1 -1
- package/dist/melonjs.mjs/_virtual/setmultimap.js +1 -1
- package/dist/melonjs.mjs/application/application.js +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- package/dist/melonjs.mjs/level/tiled/renderer/autodetect.js +1 -1
- package/dist/melonjs.mjs/loader/cache.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +2 -2
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/primitive.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/attributes.js +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +38 -32
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
370
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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 -
|
|
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 (
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
183
|
+
let s = frame.frame;
|
|
190
184
|
|
|
191
|
-
|
|
185
|
+
let originX, originY;
|
|
192
186
|
// Pixel-based offset origin from the top-left of the source frame
|
|
193
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
214
|
+
let atlas = {};
|
|
215
|
+
let image = data.image;
|
|
216
|
+
let spacing = data.spacing || 0;
|
|
217
|
+
let margin = data.margin || 0;
|
|
224
218
|
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
let width = image.width;
|
|
220
|
+
let height = image.height;
|
|
227
221
|
|
|
228
222
|
// calculate the sprite count (line, col)
|
|
229
|
-
|
|
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
|
-
|
|
238
|
-
|
|
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 (
|
|
255
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
392
|
+
if (typeof renderer.gl !== "undefined") {
|
|
399
393
|
// Source coordinates
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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 (
|
|
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 -
|
|
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/
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
117
|
-
|
|
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
|
-
|
|
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 -
|
|
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
|
-
|
|
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
|
-
|
|
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 -
|
|
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
|
-
|
|
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 -
|
|
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,
|
|
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
|
|
21
|
-
this.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
57
|
-
this.maxVertex
|
|
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
|
-
|
|
63
|
+
let data = this.bufferF32;
|
|
60
64
|
|
|
61
65
|
// recreate ArrayBuffer and views
|
|
62
|
-
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.
|
|
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
|
-
|
|
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
|
|
84
|
-
this.bufferF32[offset
|
|
87
|
+
this.bufferF32[offset] = x;
|
|
88
|
+
this.bufferF32[++offset] = y;
|
|
85
89
|
|
|
86
90
|
if (typeof u !== "undefined") {
|
|
87
|
-
this.bufferF32[offset
|
|
88
|
-
this.bufferF32[offset
|
|
91
|
+
this.bufferF32[++offset] = u;
|
|
92
|
+
this.bufferF32[++offset] = v;
|
|
89
93
|
}
|
|
90
94
|
|
|
91
95
|
if (typeof tint !== "undefined") {
|
|
92
|
-
this.bufferU32[offset
|
|
96
|
+
this.bufferU32[++offset] = tint;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
this.vertexCount++;
|