melonjs 15.0.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/README.md +4 -4
- 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 +17 -17
- 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 +53 -53
- 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 +5 -5
- 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 +58 -58
- 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 +21 -21
- 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 +11 -11
- 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 -63
- 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 +2 -2
- 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 +10 -9
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- 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 +35 -109
- package/dist/melonjs.mjs/video/renderer.js +74 -7
- package/dist/melonjs.mjs/video/texture/atlas.js +37 -37
- 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 +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +18 -15
- 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 +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +1 -1
- 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 +55 -38
- package/dist/melonjs.module.js +1747 -1809
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/index.d.ts +4 -3
- 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/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 -11
- 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 +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -76
- package/dist/types/video/renderer.d.ts +48 -0
- 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/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +13 -9
- package/package.json +14 -14
- 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 +16 -16
- 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 +52 -52
- 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 +3 -2
- 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 +20 -20
- 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/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 +10 -10
- 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 -65
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +1 -1
- 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 +9 -8
- package/src/text/textmetrics.js +14 -14
- 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 +34 -108
- package/src/video/renderer.js +72 -5
- package/src/video/texture/atlas.js +36 -36
- 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 +2 -2
- package/src/video/webgl/compositors/compositor.js +4 -4
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +17 -14
- package/src/video/webgl/glshader.js +6 -6
- 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 +54 -37
|
@@ -68,8 +68,6 @@ import * as event from "./../../system/event.js";
|
|
|
68
68
|
|
|
69
69
|
/**
|
|
70
70
|
* Reset context state
|
|
71
|
-
* @name reset
|
|
72
|
-
* @memberof CanvasRenderer
|
|
73
71
|
*/
|
|
74
72
|
reset() {
|
|
75
73
|
super.reset();
|
|
@@ -78,8 +76,6 @@ import * as event from "./../../system/event.js";
|
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
78
|
* Reset the canvas transform to identity
|
|
81
|
-
* @name resetTransform
|
|
82
|
-
* @memberof CanvasRenderer
|
|
83
79
|
*/
|
|
84
80
|
resetTransform() {
|
|
85
81
|
this.getContext().setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -96,9 +92,7 @@ import * as event from "./../../system/event.js";
|
|
|
96
92
|
* <img src="images/lighter-blendmode.png" width="510"/> <br>
|
|
97
93
|
* - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
|
|
98
94
|
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
99
|
-
* @name setBlendMode
|
|
100
95
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
101
|
-
* @memberof CanvasRenderer
|
|
102
96
|
* @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter, "additive", "screen"
|
|
103
97
|
* @param {CanvasRenderingContext2D} [context]
|
|
104
98
|
*/
|
|
@@ -128,27 +122,23 @@ import * as event from "./../../system/event.js";
|
|
|
128
122
|
|
|
129
123
|
/**
|
|
130
124
|
* prepare the framebuffer for drawing a new frame
|
|
131
|
-
* @name clear
|
|
132
|
-
* @memberof CanvasRenderer
|
|
133
125
|
*/
|
|
134
126
|
clear() {
|
|
135
127
|
if (this.settings.transparent === false) {
|
|
136
|
-
|
|
137
|
-
|
|
128
|
+
let canvas = this.getCanvas();
|
|
129
|
+
let context = this.getContext();
|
|
138
130
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
139
131
|
}
|
|
140
132
|
}
|
|
141
133
|
|
|
142
134
|
/**
|
|
143
135
|
* Clears the main framebuffer with the given color
|
|
144
|
-
* @name clearColor
|
|
145
|
-
* @memberof CanvasRenderer
|
|
146
136
|
* @param {Color|string} [color="#000000"] - CSS color.
|
|
147
137
|
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
148
138
|
*/
|
|
149
139
|
clearColor(color = "#000000", opaque = false) {
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
let canvas = this.getCanvas();
|
|
141
|
+
let context = this.getContext();
|
|
152
142
|
|
|
153
143
|
this.save();
|
|
154
144
|
this.resetTransform();
|
|
@@ -161,8 +151,6 @@ import * as event from "./../../system/event.js";
|
|
|
161
151
|
|
|
162
152
|
/**
|
|
163
153
|
* Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
|
|
164
|
-
* @name clearRect
|
|
165
|
-
* @memberof CanvasRenderer
|
|
166
154
|
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
167
155
|
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
168
156
|
* @param {number} width - The rectangle's width.
|
|
@@ -174,17 +162,15 @@ import * as event from "./../../system/event.js";
|
|
|
174
162
|
|
|
175
163
|
/**
|
|
176
164
|
* Create a pattern with the specified repetition
|
|
177
|
-
* @
|
|
178
|
-
* @memberof CanvasRenderer
|
|
179
|
-
* @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
|
|
180
166
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
181
167
|
* @returns {CanvasPattern}
|
|
182
168
|
* @see ImageLayer#repeat
|
|
183
169
|
* @example
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
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");
|
|
188
174
|
*/
|
|
189
175
|
createPattern(image, repeat) {
|
|
190
176
|
return this.getContext().createPattern(image, repeat);
|
|
@@ -192,9 +178,7 @@ import * as event from "./../../system/event.js";
|
|
|
192
178
|
|
|
193
179
|
/**
|
|
194
180
|
* Draw an image onto the main using the canvas api
|
|
195
|
-
* @
|
|
196
|
-
* @memberof CanvasRenderer
|
|
197
|
-
* @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.
|
|
198
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.
|
|
199
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.
|
|
200
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.
|
|
@@ -216,7 +200,7 @@ import * as event from "./../../system/event.js";
|
|
|
216
200
|
// Fast path: don't draw fully transparent
|
|
217
201
|
return;
|
|
218
202
|
}
|
|
219
|
-
|
|
203
|
+
let context = this.getContext();
|
|
220
204
|
|
|
221
205
|
if (typeof sw === "undefined") {
|
|
222
206
|
sw = dw = image.width;
|
|
@@ -244,8 +228,8 @@ import * as event from "./../../system/event.js";
|
|
|
244
228
|
}
|
|
245
229
|
|
|
246
230
|
// apply a tint if required
|
|
247
|
-
|
|
248
|
-
|
|
231
|
+
let source = image;
|
|
232
|
+
let tint = this.currentTint.toArray();
|
|
249
233
|
if (tint[0] !== 1.0 || tint[1] !== 1.0 || tint[2] !== 1.0) {
|
|
250
234
|
// get a tinted version of this image from the texture cache
|
|
251
235
|
source = this.cache.tint(image, this.currentTint.toRGB());
|
|
@@ -255,8 +239,6 @@ import * as event from "./../../system/event.js";
|
|
|
255
239
|
|
|
256
240
|
/**
|
|
257
241
|
* Draw a pattern within the given rectangle.
|
|
258
|
-
* @name drawPattern
|
|
259
|
-
* @memberof CanvasRenderer
|
|
260
242
|
* @param {CanvasPattern} pattern - Pattern object
|
|
261
243
|
* @param {number} x
|
|
262
244
|
* @param {number} y
|
|
@@ -269,8 +251,8 @@ import * as event from "./../../system/event.js";
|
|
|
269
251
|
// Fast path: don't draw fully transparent
|
|
270
252
|
return;
|
|
271
253
|
}
|
|
272
|
-
|
|
273
|
-
|
|
254
|
+
let context = this.getContext();
|
|
255
|
+
let fillStyle = context.fillStyle;
|
|
274
256
|
context.fillStyle = pattern;
|
|
275
257
|
context.fillRect(x, y, width, height);
|
|
276
258
|
context.fillStyle = fillStyle;
|
|
@@ -278,8 +260,6 @@ import * as event from "./../../system/event.js";
|
|
|
278
260
|
|
|
279
261
|
/**
|
|
280
262
|
* Stroke an arc at the specified coordinates with given radius, start and end points
|
|
281
|
-
* @name strokeArc
|
|
282
|
-
* @memberof CanvasRenderer
|
|
283
263
|
* @param {number} x - arc center point x-axis
|
|
284
264
|
* @param {number} y - arc center point y-axis
|
|
285
265
|
* @param {number} radius
|
|
@@ -293,7 +273,7 @@ import * as event from "./../../system/event.js";
|
|
|
293
273
|
// Fast path: don't draw fully transparent
|
|
294
274
|
return;
|
|
295
275
|
}
|
|
296
|
-
|
|
276
|
+
let context = this.getContext();
|
|
297
277
|
|
|
298
278
|
context.translate(x, y);
|
|
299
279
|
context.beginPath();
|
|
@@ -304,8 +284,6 @@ import * as event from "./../../system/event.js";
|
|
|
304
284
|
|
|
305
285
|
/**
|
|
306
286
|
* Fill an arc at the specified coordinates with given radius, start and end points
|
|
307
|
-
* @name fillArc
|
|
308
|
-
* @memberof CanvasRenderer
|
|
309
287
|
* @param {number} x - arc center point x-axis
|
|
310
288
|
* @param {number} y - arc center point y-axis
|
|
311
289
|
* @param {number} radius
|
|
@@ -319,8 +297,6 @@ import * as event from "./../../system/event.js";
|
|
|
319
297
|
|
|
320
298
|
/**
|
|
321
299
|
* Stroke an ellipse at the specified coordinates with given radius
|
|
322
|
-
* @name strokeEllipse
|
|
323
|
-
* @memberof CanvasRenderer
|
|
324
300
|
* @param {number} x - ellipse center point x-axis
|
|
325
301
|
* @param {number} y - ellipse center point y-axis
|
|
326
302
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -332,16 +308,16 @@ import * as event from "./../../system/event.js";
|
|
|
332
308
|
// Fast path: don't draw fully transparent
|
|
333
309
|
return;
|
|
334
310
|
}
|
|
335
|
-
|
|
311
|
+
let context = this.getContext();
|
|
336
312
|
|
|
337
|
-
|
|
313
|
+
let hw = w,
|
|
338
314
|
hh = h,
|
|
339
315
|
lx = x - hw,
|
|
340
316
|
rx = x + hw,
|
|
341
317
|
ty = y - hh,
|
|
342
318
|
by = y + hh;
|
|
343
319
|
|
|
344
|
-
|
|
320
|
+
let xmagic = hw * 0.551784,
|
|
345
321
|
ymagic = hh * 0.551784,
|
|
346
322
|
xmin = x - xmagic,
|
|
347
323
|
xmax = x + xmagic,
|
|
@@ -360,8 +336,6 @@ import * as event from "./../../system/event.js";
|
|
|
360
336
|
|
|
361
337
|
/**
|
|
362
338
|
* Fill an ellipse at the specified coordinates with given radius
|
|
363
|
-
* @name fillEllipse
|
|
364
|
-
* @memberof CanvasRenderer
|
|
365
339
|
* @param {number} x - ellipse center point x-axis
|
|
366
340
|
* @param {number} y - ellipse center point y-axis
|
|
367
341
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -373,8 +347,6 @@ import * as event from "./../../system/event.js";
|
|
|
373
347
|
|
|
374
348
|
/**
|
|
375
349
|
* Stroke a line of the given two points
|
|
376
|
-
* @name strokeLine
|
|
377
|
-
* @memberof CanvasRenderer
|
|
378
350
|
* @param {number} startX - the start x coordinate
|
|
379
351
|
* @param {number} startY - the start y coordinate
|
|
380
352
|
* @param {number} endX - the end x coordinate
|
|
@@ -386,7 +358,7 @@ import * as event from "./../../system/event.js";
|
|
|
386
358
|
return;
|
|
387
359
|
}
|
|
388
360
|
|
|
389
|
-
|
|
361
|
+
let context = this.getContext();
|
|
390
362
|
|
|
391
363
|
context.beginPath();
|
|
392
364
|
context.moveTo(startX, startY);
|
|
@@ -396,8 +368,6 @@ import * as event from "./../../system/event.js";
|
|
|
396
368
|
|
|
397
369
|
/**
|
|
398
370
|
* Fill a line of the given two points
|
|
399
|
-
* @name fillLine
|
|
400
|
-
* @memberof CanvasRenderer
|
|
401
371
|
* @param {number} startX - the start x coordinate
|
|
402
372
|
* @param {number} startY - the start y coordinate
|
|
403
373
|
* @param {number} endX - the end x coordinate
|
|
@@ -409,8 +379,6 @@ import * as event from "./../../system/event.js";
|
|
|
409
379
|
|
|
410
380
|
/**
|
|
411
381
|
* Stroke the given me.Polygon on the screen
|
|
412
|
-
* @name strokePolygon
|
|
413
|
-
* @memberof CanvasRenderer
|
|
414
382
|
* @param {Polygon} poly - the shape to draw
|
|
415
383
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
416
384
|
*/
|
|
@@ -419,13 +387,13 @@ import * as event from "./../../system/event.js";
|
|
|
419
387
|
// Fast path: don't draw fully transparent
|
|
420
388
|
return;
|
|
421
389
|
}
|
|
422
|
-
|
|
390
|
+
let context = this.getContext();
|
|
423
391
|
|
|
424
392
|
this.translate(poly.pos.x, poly.pos.y);
|
|
425
393
|
context.beginPath();
|
|
426
394
|
context.moveTo(poly.points[0].x, poly.points[0].y);
|
|
427
|
-
|
|
428
|
-
for (
|
|
395
|
+
let point;
|
|
396
|
+
for (let i = 1; i < poly.points.length; i++) {
|
|
429
397
|
point = poly.points[i];
|
|
430
398
|
context.lineTo(point.x, point.y);
|
|
431
399
|
}
|
|
@@ -437,8 +405,6 @@ import * as event from "./../../system/event.js";
|
|
|
437
405
|
|
|
438
406
|
/**
|
|
439
407
|
* Fill the given me.Polygon on the screen
|
|
440
|
-
* @name fillPolygon
|
|
441
|
-
* @memberof CanvasRenderer
|
|
442
408
|
* @param {Polygon} poly - the shape to draw
|
|
443
409
|
*/
|
|
444
410
|
fillPolygon(poly) {
|
|
@@ -447,8 +413,6 @@ import * as event from "./../../system/event.js";
|
|
|
447
413
|
|
|
448
414
|
/**
|
|
449
415
|
* Stroke a rectangle at the specified coordinates
|
|
450
|
-
* @name strokeRect
|
|
451
|
-
* @memberof CanvasRenderer
|
|
452
416
|
* @param {number} x
|
|
453
417
|
* @param {number} y
|
|
454
418
|
* @param {number} width
|
|
@@ -460,15 +424,13 @@ import * as event from "./../../system/event.js";
|
|
|
460
424
|
// Fast path: don't draw fully transparent
|
|
461
425
|
return;
|
|
462
426
|
}
|
|
463
|
-
|
|
427
|
+
let context = this.getContext();
|
|
464
428
|
|
|
465
429
|
context[fill === true ? "fillRect" : "strokeRect"](x, y, width, height);
|
|
466
430
|
}
|
|
467
431
|
|
|
468
432
|
/**
|
|
469
433
|
* Draw a filled rectangle at the specified coordinates
|
|
470
|
-
* @name fillRect
|
|
471
|
-
* @memberof CanvasRenderer
|
|
472
434
|
* @param {number} x
|
|
473
435
|
* @param {number} y
|
|
474
436
|
* @param {number} width
|
|
@@ -480,8 +442,6 @@ import * as event from "./../../system/event.js";
|
|
|
480
442
|
|
|
481
443
|
/**
|
|
482
444
|
* Stroke a rounded rectangle at the specified coordinates
|
|
483
|
-
* @name strokeRoundRect
|
|
484
|
-
* @memberof CanvasRenderer
|
|
485
445
|
* @param {number} x
|
|
486
446
|
* @param {number} y
|
|
487
447
|
* @param {number} width
|
|
@@ -494,7 +454,7 @@ import * as event from "./../../system/event.js";
|
|
|
494
454
|
// Fast path: don't draw fully transparent
|
|
495
455
|
return;
|
|
496
456
|
}
|
|
497
|
-
|
|
457
|
+
let context = this.getContext();
|
|
498
458
|
|
|
499
459
|
context.beginPath();
|
|
500
460
|
context.roundRect(x, y, width, height, radius);
|
|
@@ -503,8 +463,6 @@ import * as event from "./../../system/event.js";
|
|
|
503
463
|
|
|
504
464
|
/**
|
|
505
465
|
* Draw a rounded filled rectangle at the specified coordinates
|
|
506
|
-
* @name fillRoundRect
|
|
507
|
-
* @memberof CanvasRenderer
|
|
508
466
|
* @param {number} x
|
|
509
467
|
* @param {number} y
|
|
510
468
|
* @param {number} width
|
|
@@ -517,8 +475,6 @@ import * as event from "./../../system/event.js";
|
|
|
517
475
|
|
|
518
476
|
/**
|
|
519
477
|
* Stroke a Point at the specified coordinates
|
|
520
|
-
* @name strokePoint
|
|
521
|
-
* @memberof CanvasRenderer
|
|
522
478
|
* @param {number} x
|
|
523
479
|
* @param {number} y
|
|
524
480
|
*/
|
|
@@ -528,8 +484,6 @@ import * as event from "./../../system/event.js";
|
|
|
528
484
|
|
|
529
485
|
/**
|
|
530
486
|
* Draw a a point at the specified coordinates
|
|
531
|
-
* @name fillPoint
|
|
532
|
-
* @memberof CanvasRenderer
|
|
533
487
|
* @param {number} x
|
|
534
488
|
* @param {number} y
|
|
535
489
|
* @param {number} width
|
|
@@ -541,8 +495,6 @@ import * as event from "./../../system/event.js";
|
|
|
541
495
|
|
|
542
496
|
/**
|
|
543
497
|
* save the canvas context
|
|
544
|
-
* @name save
|
|
545
|
-
* @memberof CanvasRenderer
|
|
546
498
|
*/
|
|
547
499
|
save() {
|
|
548
500
|
this.getContext().save();
|
|
@@ -550,8 +502,6 @@ import * as event from "./../../system/event.js";
|
|
|
550
502
|
|
|
551
503
|
/**
|
|
552
504
|
* restores the canvas context
|
|
553
|
-
* @name restore
|
|
554
|
-
* @memberof CanvasRenderer
|
|
555
505
|
*/
|
|
556
506
|
restore() {
|
|
557
507
|
this.getContext().restore();
|
|
@@ -564,8 +514,6 @@ import * as event from "./../../system/event.js";
|
|
|
564
514
|
|
|
565
515
|
/**
|
|
566
516
|
* rotates the canvas context
|
|
567
|
-
* @name rotate
|
|
568
|
-
* @memberof CanvasRenderer
|
|
569
517
|
* @param {number} angle - in radians
|
|
570
518
|
*/
|
|
571
519
|
rotate(angle) {
|
|
@@ -574,8 +522,6 @@ import * as event from "./../../system/event.js";
|
|
|
574
522
|
|
|
575
523
|
/**
|
|
576
524
|
* scales the canvas context
|
|
577
|
-
* @name scale
|
|
578
|
-
* @memberof CanvasRenderer
|
|
579
525
|
* @param {number} x
|
|
580
526
|
* @param {number} y
|
|
581
527
|
*/
|
|
@@ -586,12 +532,10 @@ import * as event from "./../../system/event.js";
|
|
|
586
532
|
/**
|
|
587
533
|
* Set the current fill & stroke style color.
|
|
588
534
|
* By default, or upon reset, the value is set to #000000.
|
|
589
|
-
* @name setColor
|
|
590
|
-
* @memberof CanvasRenderer
|
|
591
535
|
* @param {Color|string} color - css color value
|
|
592
536
|
*/
|
|
593
537
|
setColor(color) {
|
|
594
|
-
|
|
538
|
+
let context = this.getContext();
|
|
595
539
|
context.strokeStyle =
|
|
596
540
|
context.fillStyle = (
|
|
597
541
|
color instanceof Color ?
|
|
@@ -602,8 +546,6 @@ import * as event from "./../../system/event.js";
|
|
|
602
546
|
|
|
603
547
|
/**
|
|
604
548
|
* Set the global alpha
|
|
605
|
-
* @name setGlobalAlpha
|
|
606
|
-
* @memberof CanvasRenderer
|
|
607
549
|
* @param {number} alpha - 0.0 to 1.0 values accepted.
|
|
608
550
|
*/
|
|
609
551
|
setGlobalAlpha(alpha) {
|
|
@@ -612,8 +554,6 @@ import * as event from "./../../system/event.js";
|
|
|
612
554
|
|
|
613
555
|
/**
|
|
614
556
|
* Return the global alpha
|
|
615
|
-
* @name getGlobalAlpha
|
|
616
|
-
* @memberof CanvasRenderer
|
|
617
557
|
* @returns {number} global alpha value
|
|
618
558
|
*/
|
|
619
559
|
getGlobalAlpha() {
|
|
@@ -622,8 +562,6 @@ import * as event from "./../../system/event.js";
|
|
|
622
562
|
|
|
623
563
|
/**
|
|
624
564
|
* Set the line width on the context
|
|
625
|
-
* @name setLineWidth
|
|
626
|
-
* @memberof CanvasRenderer
|
|
627
565
|
* @param {number} width - Line width
|
|
628
566
|
*/
|
|
629
567
|
setLineWidth(width) {
|
|
@@ -633,8 +571,6 @@ import * as event from "./../../system/event.js";
|
|
|
633
571
|
/**
|
|
634
572
|
* Reset (overrides) the renderer transformation matrix to the
|
|
635
573
|
* identity one, and then apply the given transformation matrix.
|
|
636
|
-
* @name setTransform
|
|
637
|
-
* @memberof CanvasRenderer
|
|
638
574
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
639
575
|
*/
|
|
640
576
|
setTransform(mat2d) {
|
|
@@ -644,12 +580,10 @@ import * as event from "./../../system/event.js";
|
|
|
644
580
|
|
|
645
581
|
/**
|
|
646
582
|
* Multiply given matrix into the renderer tranformation matrix
|
|
647
|
-
* @name transform
|
|
648
|
-
* @memberof CanvasRenderer
|
|
649
583
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
650
584
|
*/
|
|
651
585
|
transform(mat2d) {
|
|
652
|
-
|
|
586
|
+
let m = mat2d.toArray(),
|
|
653
587
|
a = m[0],
|
|
654
588
|
b = m[1],
|
|
655
589
|
c = m[3],
|
|
@@ -667,8 +601,6 @@ import * as event from "./../../system/event.js";
|
|
|
667
601
|
|
|
668
602
|
/**
|
|
669
603
|
* Translates the context to the given position
|
|
670
|
-
* @name translate
|
|
671
|
-
* @memberof CanvasRenderer
|
|
672
604
|
* @param {number} x
|
|
673
605
|
* @param {number} y
|
|
674
606
|
*/
|
|
@@ -686,22 +618,20 @@ import * as event from "./../../system/event.js";
|
|
|
686
618
|
* You can however save the current region using the save(),
|
|
687
619
|
* and restore it (with the restore() method) any time in the future.
|
|
688
620
|
* (<u>this is an experimental feature !</u>)
|
|
689
|
-
* @name clipRect
|
|
690
|
-
* @memberof CanvasRenderer
|
|
691
621
|
* @param {number} x
|
|
692
622
|
* @param {number} y
|
|
693
623
|
* @param {number} width
|
|
694
624
|
* @param {number} height
|
|
695
625
|
*/
|
|
696
626
|
clipRect(x, y, width, height) {
|
|
697
|
-
|
|
627
|
+
let canvas = this.getCanvas();
|
|
698
628
|
// if requested box is different from the current canvas size;
|
|
699
629
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
700
|
-
|
|
630
|
+
let currentScissor = this.currentScissor;
|
|
701
631
|
// if different from the current scissor box
|
|
702
632
|
if (currentScissor[0] !== x || currentScissor[1] !== y ||
|
|
703
633
|
currentScissor[2] !== width || currentScissor[3] !== height) {
|
|
704
|
-
|
|
634
|
+
let context = this.getContext();
|
|
705
635
|
context.beginPath();
|
|
706
636
|
context.rect(x, y, width, height);
|
|
707
637
|
context.clip();
|
|
@@ -718,13 +648,11 @@ import * as event from "./../../system/event.js";
|
|
|
718
648
|
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
719
649
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
720
650
|
* Mask are not preserved through renderer context save and restore.
|
|
721
|
-
* @name setMask
|
|
722
|
-
* @memberof CanvasRenderer
|
|
723
651
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - the shape defining the mask to be applied
|
|
724
652
|
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
725
653
|
*/
|
|
726
654
|
setMask(mask, invert = false) {
|
|
727
|
-
|
|
655
|
+
let context = this.getContext();
|
|
728
656
|
|
|
729
657
|
if (this.maskLevel === 0) {
|
|
730
658
|
// only save context on the first mask
|
|
@@ -746,7 +674,7 @@ import * as event from "./../../system/event.js";
|
|
|
746
674
|
ty = _y - hh,
|
|
747
675
|
by = _y + hh;
|
|
748
676
|
|
|
749
|
-
|
|
677
|
+
let xmagic = hw * 0.551784,
|
|
750
678
|
ymagic = hh * 0.551784,
|
|
751
679
|
xmin = _x - xmagic,
|
|
752
680
|
xmax = _x + xmagic,
|
|
@@ -761,10 +689,10 @@ import * as event from "./../../system/event.js";
|
|
|
761
689
|
} else {
|
|
762
690
|
// polygon
|
|
763
691
|
const _x = mask.pos.x, _y = mask.pos.y;
|
|
764
|
-
|
|
692
|
+
let point;
|
|
765
693
|
|
|
766
694
|
context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
|
|
767
|
-
for (
|
|
695
|
+
for (let i = 1; i < mask.points.length; i++) {
|
|
768
696
|
point = mask.points[i];
|
|
769
697
|
context.lineTo(_x + point.x, _y + point.y);
|
|
770
698
|
}
|
|
@@ -783,9 +711,7 @@ import * as event from "./../../system/event.js";
|
|
|
783
711
|
|
|
784
712
|
/**
|
|
785
713
|
* disable (remove) the rendering mask set through setMask.
|
|
786
|
-
* @name clearMask
|
|
787
714
|
* @see CanvasRenderer#setMask
|
|
788
|
-
* @memberof CanvasRenderer
|
|
789
715
|
*/
|
|
790
716
|
clearMask() {
|
|
791
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}
|
|
@@ -193,7 +202,7 @@ import Point from "../geometries/point.js";
|
|
|
193
202
|
transparent = true;
|
|
194
203
|
}
|
|
195
204
|
|
|
196
|
-
|
|
205
|
+
let _context = canvas.getContext("2d", {
|
|
197
206
|
"alpha" : transparent
|
|
198
207
|
});
|
|
199
208
|
|
|
@@ -255,7 +264,7 @@ import Point from "../geometries/point.js";
|
|
|
255
264
|
* @param {number} height - new height of the canvas
|
|
256
265
|
*/
|
|
257
266
|
resize(width, height) {
|
|
258
|
-
|
|
267
|
+
let canvas = this.getCanvas();
|
|
259
268
|
if (width !== canvas.width || height !== canvas.height) {
|
|
260
269
|
canvas.width = width;
|
|
261
270
|
canvas.height = height;
|
|
@@ -274,7 +283,7 @@ import Point from "../geometries/point.js";
|
|
|
274
283
|
* @param {boolean} [enable=false]
|
|
275
284
|
*/
|
|
276
285
|
setAntiAlias(context, enable) {
|
|
277
|
-
|
|
286
|
+
let canvas = context.canvas;
|
|
278
287
|
|
|
279
288
|
// enable/disable antialis on the given Context2d object
|
|
280
289
|
setPrefixed("imageSmoothingEnabled", enable === true, context);
|
|
@@ -354,8 +363,8 @@ import Point from "../geometries/point.js";
|
|
|
354
363
|
* @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
|
|
355
364
|
*/
|
|
356
365
|
tint(src, color, mode) {
|
|
357
|
-
|
|
358
|
-
|
|
366
|
+
let canvas = createCanvas(src.width, src.height, true);
|
|
367
|
+
let context = this.getContext2d(canvas);
|
|
359
368
|
|
|
360
369
|
context.save();
|
|
361
370
|
|
|
@@ -407,4 +416,62 @@ import Point from "../geometries/point.js";
|
|
|
407
416
|
// reset to default
|
|
408
417
|
this.currentTint.setColor(255, 255, 255, 1.0);
|
|
409
418
|
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
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));
|
|
448
|
+
*/
|
|
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
|
+
}
|
|
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
|
+
}
|
|
410
477
|
}
|