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
|
@@ -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
|
-
|
|
132
|
-
|
|
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
|
-
|
|
146
|
-
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
|
|
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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
268
|
-
|
|
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
|
-
|
|
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
|
-
|
|
311
|
+
let context = this.getContext();
|
|
331
312
|
|
|
332
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
423
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
692
|
+
let point;
|
|
769
693
|
|
|
770
694
|
context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
|
|
771
|
-
for (
|
|
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) {
|
package/src/video/renderer.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
363
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
}
|