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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
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
|
|
@@ -75,8 +75,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Reset context state
|
|
78
|
-
* @name reset
|
|
79
|
-
* @memberof CanvasRenderer
|
|
80
78
|
*/
|
|
81
79
|
reset() {
|
|
82
80
|
super.reset();
|
|
@@ -85,8 +83,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
85
83
|
|
|
86
84
|
/**
|
|
87
85
|
* Reset the canvas transform to identity
|
|
88
|
-
* @name resetTransform
|
|
89
|
-
* @memberof CanvasRenderer
|
|
90
86
|
*/
|
|
91
87
|
resetTransform() {
|
|
92
88
|
this.getContext().setTransform(1, 0, 0, 1, 0, 0);
|
|
@@ -103,9 +99,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
103
99
|
* <img src="images/lighter-blendmode.png" width="510"/> <br>
|
|
104
100
|
* - "screen" : The pixels are inverted, multiplied, and inverted again. A lighter picture is the result (opposite of multiply) <br>
|
|
105
101
|
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
106
|
-
* @name setBlendMode
|
|
107
102
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
108
|
-
* @memberof CanvasRenderer
|
|
109
103
|
* @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter, "additive", "screen"
|
|
110
104
|
* @param {CanvasRenderingContext2D} [context]
|
|
111
105
|
*/
|
|
@@ -135,27 +129,23 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
135
129
|
|
|
136
130
|
/**
|
|
137
131
|
* prepare the framebuffer for drawing a new frame
|
|
138
|
-
* @name clear
|
|
139
|
-
* @memberof CanvasRenderer
|
|
140
132
|
*/
|
|
141
133
|
clear() {
|
|
142
134
|
if (this.settings.transparent === false) {
|
|
143
|
-
|
|
144
|
-
|
|
135
|
+
let canvas = this.getCanvas();
|
|
136
|
+
let context = this.getContext();
|
|
145
137
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
146
138
|
}
|
|
147
139
|
}
|
|
148
140
|
|
|
149
141
|
/**
|
|
150
142
|
* Clears the main framebuffer with the given color
|
|
151
|
-
* @name clearColor
|
|
152
|
-
* @memberof CanvasRenderer
|
|
153
143
|
* @param {Color|string} [color="#000000"] - CSS color.
|
|
154
144
|
* @param {boolean} [opaque=false] - Allow transparency [default] or clear the surface completely [true]
|
|
155
145
|
*/
|
|
156
146
|
clearColor(color = "#000000", opaque = false) {
|
|
157
|
-
|
|
158
|
-
|
|
147
|
+
let canvas = this.getCanvas();
|
|
148
|
+
let context = this.getContext();
|
|
159
149
|
|
|
160
150
|
this.save();
|
|
161
151
|
this.resetTransform();
|
|
@@ -168,8 +158,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
168
158
|
|
|
169
159
|
/**
|
|
170
160
|
* Erase the pixels in the given rectangular area by setting them to transparent black (rgba(0,0,0,0)).
|
|
171
|
-
* @name clearRect
|
|
172
|
-
* @memberof CanvasRenderer
|
|
173
161
|
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
174
162
|
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
175
163
|
* @param {number} width - The rectangle's width.
|
|
@@ -181,17 +169,15 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
181
169
|
|
|
182
170
|
/**
|
|
183
171
|
* Create a pattern with the specified repetition
|
|
184
|
-
* @
|
|
185
|
-
* @memberof CanvasRenderer
|
|
186
|
-
* @param {Image} image - Source image
|
|
172
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
187
173
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
188
174
|
* @returns {CanvasPattern}
|
|
189
175
|
* @see ImageLayer#repeat
|
|
190
176
|
* @example
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
177
|
+
* let tileable = renderer.createPattern(image, "repeat");
|
|
178
|
+
* let horizontal = renderer.createPattern(image, "repeat-x");
|
|
179
|
+
* let vertical = renderer.createPattern(image, "repeat-y");
|
|
180
|
+
* let basic = renderer.createPattern(image, "no-repeat");
|
|
195
181
|
*/
|
|
196
182
|
createPattern(image, repeat) {
|
|
197
183
|
return this.getContext().createPattern(image, repeat);
|
|
@@ -199,9 +185,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
199
185
|
|
|
200
186
|
/**
|
|
201
187
|
* Draw an image onto the main using the canvas api
|
|
202
|
-
* @
|
|
203
|
-
* @memberof CanvasRenderer
|
|
204
|
-
* @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.
|
|
188
|
+
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - An element to draw into the context.
|
|
205
189
|
* @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.
|
|
206
190
|
* @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.
|
|
207
191
|
* @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.
|
|
@@ -223,7 +207,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
223
207
|
// Fast path: don't draw fully transparent
|
|
224
208
|
return;
|
|
225
209
|
}
|
|
226
|
-
|
|
210
|
+
let context = this.getContext();
|
|
227
211
|
|
|
228
212
|
if (typeof sw === "undefined") {
|
|
229
213
|
sw = dw = image.width;
|
|
@@ -251,8 +235,8 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
251
235
|
}
|
|
252
236
|
|
|
253
237
|
// apply a tint if required
|
|
254
|
-
|
|
255
|
-
|
|
238
|
+
let source = image;
|
|
239
|
+
let tint = this.currentTint.toArray();
|
|
256
240
|
if (tint[0] !== 1.0 || tint[1] !== 1.0 || tint[2] !== 1.0) {
|
|
257
241
|
// get a tinted version of this image from the texture cache
|
|
258
242
|
source = this.cache.tint(image, this.currentTint.toRGB());
|
|
@@ -262,8 +246,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
262
246
|
|
|
263
247
|
/**
|
|
264
248
|
* Draw a pattern within the given rectangle.
|
|
265
|
-
* @name drawPattern
|
|
266
|
-
* @memberof CanvasRenderer
|
|
267
249
|
* @param {CanvasPattern} pattern - Pattern object
|
|
268
250
|
* @param {number} x
|
|
269
251
|
* @param {number} y
|
|
@@ -276,8 +258,8 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
276
258
|
// Fast path: don't draw fully transparent
|
|
277
259
|
return;
|
|
278
260
|
}
|
|
279
|
-
|
|
280
|
-
|
|
261
|
+
let context = this.getContext();
|
|
262
|
+
let fillStyle = context.fillStyle;
|
|
281
263
|
context.fillStyle = pattern;
|
|
282
264
|
context.fillRect(x, y, width, height);
|
|
283
265
|
context.fillStyle = fillStyle;
|
|
@@ -285,8 +267,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
285
267
|
|
|
286
268
|
/**
|
|
287
269
|
* Stroke an arc at the specified coordinates with given radius, start and end points
|
|
288
|
-
* @name strokeArc
|
|
289
|
-
* @memberof CanvasRenderer
|
|
290
270
|
* @param {number} x - arc center point x-axis
|
|
291
271
|
* @param {number} y - arc center point y-axis
|
|
292
272
|
* @param {number} radius
|
|
@@ -300,7 +280,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
300
280
|
// Fast path: don't draw fully transparent
|
|
301
281
|
return;
|
|
302
282
|
}
|
|
303
|
-
|
|
283
|
+
let context = this.getContext();
|
|
304
284
|
|
|
305
285
|
context.translate(x, y);
|
|
306
286
|
context.beginPath();
|
|
@@ -311,8 +291,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
311
291
|
|
|
312
292
|
/**
|
|
313
293
|
* Fill an arc at the specified coordinates with given radius, start and end points
|
|
314
|
-
* @name fillArc
|
|
315
|
-
* @memberof CanvasRenderer
|
|
316
294
|
* @param {number} x - arc center point x-axis
|
|
317
295
|
* @param {number} y - arc center point y-axis
|
|
318
296
|
* @param {number} radius
|
|
@@ -326,8 +304,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
326
304
|
|
|
327
305
|
/**
|
|
328
306
|
* Stroke an ellipse at the specified coordinates with given radius
|
|
329
|
-
* @name strokeEllipse
|
|
330
|
-
* @memberof CanvasRenderer
|
|
331
307
|
* @param {number} x - ellipse center point x-axis
|
|
332
308
|
* @param {number} y - ellipse center point y-axis
|
|
333
309
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -339,16 +315,16 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
339
315
|
// Fast path: don't draw fully transparent
|
|
340
316
|
return;
|
|
341
317
|
}
|
|
342
|
-
|
|
318
|
+
let context = this.getContext();
|
|
343
319
|
|
|
344
|
-
|
|
320
|
+
let hw = w,
|
|
345
321
|
hh = h,
|
|
346
322
|
lx = x - hw,
|
|
347
323
|
rx = x + hw,
|
|
348
324
|
ty = y - hh,
|
|
349
325
|
by = y + hh;
|
|
350
326
|
|
|
351
|
-
|
|
327
|
+
let xmagic = hw * 0.551784,
|
|
352
328
|
ymagic = hh * 0.551784,
|
|
353
329
|
xmin = x - xmagic,
|
|
354
330
|
xmax = x + xmagic,
|
|
@@ -367,8 +343,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
367
343
|
|
|
368
344
|
/**
|
|
369
345
|
* Fill an ellipse at the specified coordinates with given radius
|
|
370
|
-
* @name fillEllipse
|
|
371
|
-
* @memberof CanvasRenderer
|
|
372
346
|
* @param {number} x - ellipse center point x-axis
|
|
373
347
|
* @param {number} y - ellipse center point y-axis
|
|
374
348
|
* @param {number} w - horizontal radius of the ellipse
|
|
@@ -380,8 +354,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
380
354
|
|
|
381
355
|
/**
|
|
382
356
|
* Stroke a line of the given two points
|
|
383
|
-
* @name strokeLine
|
|
384
|
-
* @memberof CanvasRenderer
|
|
385
357
|
* @param {number} startX - the start x coordinate
|
|
386
358
|
* @param {number} startY - the start y coordinate
|
|
387
359
|
* @param {number} endX - the end x coordinate
|
|
@@ -393,7 +365,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
393
365
|
return;
|
|
394
366
|
}
|
|
395
367
|
|
|
396
|
-
|
|
368
|
+
let context = this.getContext();
|
|
397
369
|
|
|
398
370
|
context.beginPath();
|
|
399
371
|
context.moveTo(startX, startY);
|
|
@@ -403,8 +375,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
403
375
|
|
|
404
376
|
/**
|
|
405
377
|
* Fill a line of the given two points
|
|
406
|
-
* @name fillLine
|
|
407
|
-
* @memberof CanvasRenderer
|
|
408
378
|
* @param {number} startX - the start x coordinate
|
|
409
379
|
* @param {number} startY - the start y coordinate
|
|
410
380
|
* @param {number} endX - the end x coordinate
|
|
@@ -416,8 +386,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
416
386
|
|
|
417
387
|
/**
|
|
418
388
|
* Stroke the given me.Polygon on the screen
|
|
419
|
-
* @name strokePolygon
|
|
420
|
-
* @memberof CanvasRenderer
|
|
421
389
|
* @param {Polygon} poly - the shape to draw
|
|
422
390
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
423
391
|
*/
|
|
@@ -426,13 +394,13 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
426
394
|
// Fast path: don't draw fully transparent
|
|
427
395
|
return;
|
|
428
396
|
}
|
|
429
|
-
|
|
397
|
+
let context = this.getContext();
|
|
430
398
|
|
|
431
399
|
this.translate(poly.pos.x, poly.pos.y);
|
|
432
400
|
context.beginPath();
|
|
433
401
|
context.moveTo(poly.points[0].x, poly.points[0].y);
|
|
434
|
-
|
|
435
|
-
for (
|
|
402
|
+
let point;
|
|
403
|
+
for (let i = 1; i < poly.points.length; i++) {
|
|
436
404
|
point = poly.points[i];
|
|
437
405
|
context.lineTo(point.x, point.y);
|
|
438
406
|
}
|
|
@@ -444,8 +412,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
444
412
|
|
|
445
413
|
/**
|
|
446
414
|
* Fill the given me.Polygon on the screen
|
|
447
|
-
* @name fillPolygon
|
|
448
|
-
* @memberof CanvasRenderer
|
|
449
415
|
* @param {Polygon} poly - the shape to draw
|
|
450
416
|
*/
|
|
451
417
|
fillPolygon(poly) {
|
|
@@ -454,8 +420,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
454
420
|
|
|
455
421
|
/**
|
|
456
422
|
* Stroke a rectangle at the specified coordinates
|
|
457
|
-
* @name strokeRect
|
|
458
|
-
* @memberof CanvasRenderer
|
|
459
423
|
* @param {number} x
|
|
460
424
|
* @param {number} y
|
|
461
425
|
* @param {number} width
|
|
@@ -467,15 +431,13 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
467
431
|
// Fast path: don't draw fully transparent
|
|
468
432
|
return;
|
|
469
433
|
}
|
|
470
|
-
|
|
434
|
+
let context = this.getContext();
|
|
471
435
|
|
|
472
436
|
context[fill === true ? "fillRect" : "strokeRect"](x, y, width, height);
|
|
473
437
|
}
|
|
474
438
|
|
|
475
439
|
/**
|
|
476
440
|
* Draw a filled rectangle at the specified coordinates
|
|
477
|
-
* @name fillRect
|
|
478
|
-
* @memberof CanvasRenderer
|
|
479
441
|
* @param {number} x
|
|
480
442
|
* @param {number} y
|
|
481
443
|
* @param {number} width
|
|
@@ -487,8 +449,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
487
449
|
|
|
488
450
|
/**
|
|
489
451
|
* Stroke a rounded rectangle at the specified coordinates
|
|
490
|
-
* @name strokeRoundRect
|
|
491
|
-
* @memberof CanvasRenderer
|
|
492
452
|
* @param {number} x
|
|
493
453
|
* @param {number} y
|
|
494
454
|
* @param {number} width
|
|
@@ -501,7 +461,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
501
461
|
// Fast path: don't draw fully transparent
|
|
502
462
|
return;
|
|
503
463
|
}
|
|
504
|
-
|
|
464
|
+
let context = this.getContext();
|
|
505
465
|
|
|
506
466
|
context.beginPath();
|
|
507
467
|
context.roundRect(x, y, width, height, radius);
|
|
@@ -510,8 +470,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
510
470
|
|
|
511
471
|
/**
|
|
512
472
|
* Draw a rounded filled rectangle at the specified coordinates
|
|
513
|
-
* @name fillRoundRect
|
|
514
|
-
* @memberof CanvasRenderer
|
|
515
473
|
* @param {number} x
|
|
516
474
|
* @param {number} y
|
|
517
475
|
* @param {number} width
|
|
@@ -524,8 +482,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
524
482
|
|
|
525
483
|
/**
|
|
526
484
|
* Stroke a Point at the specified coordinates
|
|
527
|
-
* @name strokePoint
|
|
528
|
-
* @memberof CanvasRenderer
|
|
529
485
|
* @param {number} x
|
|
530
486
|
* @param {number} y
|
|
531
487
|
*/
|
|
@@ -535,8 +491,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
535
491
|
|
|
536
492
|
/**
|
|
537
493
|
* Draw a a point at the specified coordinates
|
|
538
|
-
* @name fillPoint
|
|
539
|
-
* @memberof CanvasRenderer
|
|
540
494
|
* @param {number} x
|
|
541
495
|
* @param {number} y
|
|
542
496
|
* @param {number} width
|
|
@@ -548,8 +502,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
548
502
|
|
|
549
503
|
/**
|
|
550
504
|
* save the canvas context
|
|
551
|
-
* @name save
|
|
552
|
-
* @memberof CanvasRenderer
|
|
553
505
|
*/
|
|
554
506
|
save() {
|
|
555
507
|
this.getContext().save();
|
|
@@ -557,8 +509,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
557
509
|
|
|
558
510
|
/**
|
|
559
511
|
* restores the canvas context
|
|
560
|
-
* @name restore
|
|
561
|
-
* @memberof CanvasRenderer
|
|
562
512
|
*/
|
|
563
513
|
restore() {
|
|
564
514
|
this.getContext().restore();
|
|
@@ -571,8 +521,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
571
521
|
|
|
572
522
|
/**
|
|
573
523
|
* rotates the canvas context
|
|
574
|
-
* @name rotate
|
|
575
|
-
* @memberof CanvasRenderer
|
|
576
524
|
* @param {number} angle - in radians
|
|
577
525
|
*/
|
|
578
526
|
rotate(angle) {
|
|
@@ -581,8 +529,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
581
529
|
|
|
582
530
|
/**
|
|
583
531
|
* scales the canvas context
|
|
584
|
-
* @name scale
|
|
585
|
-
* @memberof CanvasRenderer
|
|
586
532
|
* @param {number} x
|
|
587
533
|
* @param {number} y
|
|
588
534
|
*/
|
|
@@ -593,12 +539,10 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
593
539
|
/**
|
|
594
540
|
* Set the current fill & stroke style color.
|
|
595
541
|
* By default, or upon reset, the value is set to #000000.
|
|
596
|
-
* @name setColor
|
|
597
|
-
* @memberof CanvasRenderer
|
|
598
542
|
* @param {Color|string} color - css color value
|
|
599
543
|
*/
|
|
600
544
|
setColor(color) {
|
|
601
|
-
|
|
545
|
+
let context = this.getContext();
|
|
602
546
|
context.strokeStyle =
|
|
603
547
|
context.fillStyle = (
|
|
604
548
|
color instanceof Color ?
|
|
@@ -609,8 +553,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
609
553
|
|
|
610
554
|
/**
|
|
611
555
|
* Set the global alpha
|
|
612
|
-
* @name setGlobalAlpha
|
|
613
|
-
* @memberof CanvasRenderer
|
|
614
556
|
* @param {number} alpha - 0.0 to 1.0 values accepted.
|
|
615
557
|
*/
|
|
616
558
|
setGlobalAlpha(alpha) {
|
|
@@ -619,8 +561,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
619
561
|
|
|
620
562
|
/**
|
|
621
563
|
* Return the global alpha
|
|
622
|
-
* @name getGlobalAlpha
|
|
623
|
-
* @memberof CanvasRenderer
|
|
624
564
|
* @returns {number} global alpha value
|
|
625
565
|
*/
|
|
626
566
|
getGlobalAlpha() {
|
|
@@ -629,8 +569,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
629
569
|
|
|
630
570
|
/**
|
|
631
571
|
* Set the line width on the context
|
|
632
|
-
* @name setLineWidth
|
|
633
|
-
* @memberof CanvasRenderer
|
|
634
572
|
* @param {number} width - Line width
|
|
635
573
|
*/
|
|
636
574
|
setLineWidth(width) {
|
|
@@ -640,8 +578,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
640
578
|
/**
|
|
641
579
|
* Reset (overrides) the renderer transformation matrix to the
|
|
642
580
|
* identity one, and then apply the given transformation matrix.
|
|
643
|
-
* @name setTransform
|
|
644
|
-
* @memberof CanvasRenderer
|
|
645
581
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
646
582
|
*/
|
|
647
583
|
setTransform(mat2d) {
|
|
@@ -651,12 +587,10 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
651
587
|
|
|
652
588
|
/**
|
|
653
589
|
* Multiply given matrix into the renderer tranformation matrix
|
|
654
|
-
* @name transform
|
|
655
|
-
* @memberof CanvasRenderer
|
|
656
590
|
* @param {Matrix2d} mat2d - Matrix to transform by
|
|
657
591
|
*/
|
|
658
592
|
transform(mat2d) {
|
|
659
|
-
|
|
593
|
+
let m = mat2d.toArray(),
|
|
660
594
|
a = m[0],
|
|
661
595
|
b = m[1],
|
|
662
596
|
c = m[3],
|
|
@@ -674,8 +608,6 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
674
608
|
|
|
675
609
|
/**
|
|
676
610
|
* Translates the context to the given position
|
|
677
|
-
* @name translate
|
|
678
|
-
* @memberof CanvasRenderer
|
|
679
611
|
* @param {number} x
|
|
680
612
|
* @param {number} y
|
|
681
613
|
*/
|
|
@@ -693,22 +625,20 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
693
625
|
* You can however save the current region using the save(),
|
|
694
626
|
* and restore it (with the restore() method) any time in the future.
|
|
695
627
|
* (<u>this is an experimental feature !</u>)
|
|
696
|
-
* @name clipRect
|
|
697
|
-
* @memberof CanvasRenderer
|
|
698
628
|
* @param {number} x
|
|
699
629
|
* @param {number} y
|
|
700
630
|
* @param {number} width
|
|
701
631
|
* @param {number} height
|
|
702
632
|
*/
|
|
703
633
|
clipRect(x, y, width, height) {
|
|
704
|
-
|
|
634
|
+
let canvas = this.getCanvas();
|
|
705
635
|
// if requested box is different from the current canvas size;
|
|
706
636
|
if (x !== 0 || y !== 0 || width !== canvas.width || height !== canvas.height) {
|
|
707
|
-
|
|
637
|
+
let currentScissor = this.currentScissor;
|
|
708
638
|
// if different from the current scissor box
|
|
709
639
|
if (currentScissor[0] !== x || currentScissor[1] !== y ||
|
|
710
640
|
currentScissor[2] !== width || currentScissor[3] !== height) {
|
|
711
|
-
|
|
641
|
+
let context = this.getContext();
|
|
712
642
|
context.beginPath();
|
|
713
643
|
context.rect(x, y, width, height);
|
|
714
644
|
context.clip();
|
|
@@ -725,13 +655,11 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
725
655
|
* A mask limits rendering elements to the shape and position of the given mask object.
|
|
726
656
|
* So, if the renderable is larger than the mask, only the intersecting part of the renderable will be visible.
|
|
727
657
|
* Mask are not preserved through renderer context save and restore.
|
|
728
|
-
* @name setMask
|
|
729
|
-
* @memberof CanvasRenderer
|
|
730
658
|
* @param {Rect|RoundRect|Polygon|Line|Ellipse} [mask] - the shape defining the mask to be applied
|
|
731
659
|
* @param {boolean} [invert=false] - either the given shape should define what is visible (default) or the opposite
|
|
732
660
|
*/
|
|
733
661
|
setMask(mask, invert = false) {
|
|
734
|
-
|
|
662
|
+
let context = this.getContext();
|
|
735
663
|
|
|
736
664
|
if (this.maskLevel === 0) {
|
|
737
665
|
// only save context on the first mask
|
|
@@ -753,7 +681,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
753
681
|
ty = _y - hh,
|
|
754
682
|
by = _y + hh;
|
|
755
683
|
|
|
756
|
-
|
|
684
|
+
let xmagic = hw * 0.551784,
|
|
757
685
|
ymagic = hh * 0.551784,
|
|
758
686
|
xmin = _x - xmagic,
|
|
759
687
|
xmax = _x + xmagic,
|
|
@@ -768,10 +696,10 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
768
696
|
} else {
|
|
769
697
|
// polygon
|
|
770
698
|
const _x = mask.pos.x, _y = mask.pos.y;
|
|
771
|
-
|
|
699
|
+
let point;
|
|
772
700
|
|
|
773
701
|
context.moveTo(_x + mask.points[0].x, _y + mask.points[0].y);
|
|
774
|
-
for (
|
|
702
|
+
for (let i = 1; i < mask.points.length; i++) {
|
|
775
703
|
point = mask.points[i];
|
|
776
704
|
context.lineTo(_x + point.x, _y + point.y);
|
|
777
705
|
}
|
|
@@ -790,9 +718,7 @@ import { emit, on, ONCONTEXT_LOST, ONCONTEXT_RESTORED, GAME_RESET } from '../../
|
|
|
790
718
|
|
|
791
719
|
/**
|
|
792
720
|
* disable (remove) the rendering mask set through setMask.
|
|
793
|
-
* @name clearMask
|
|
794
721
|
* @see CanvasRenderer#setMask
|
|
795
|
-
* @memberof CanvasRenderer
|
|
796
722
|
*/
|
|
797
723
|
clearMask() {
|
|
798
724
|
if (this.maskLevel > 0) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine - v15.
|
|
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 { emit, CANVAS_ONRESIZE } from '../system/event.js';
|
|
11
|
+
import { emit, once, CANVAS_ONRESIZE, GAME_AFTER_DRAW } from '../system/event.js';
|
|
12
12
|
import { platform } from '../system/device.js';
|
|
13
13
|
import { setPrefixed } from '../utils/agent.js';
|
|
14
14
|
import Rect from '../geometries/rectangle.js';
|
|
@@ -36,6 +36,7 @@ import Point from '../geometries/point.js';
|
|
|
36
36
|
* @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
|
|
37
37
|
* @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
|
|
38
38
|
* @param {boolean} [options.blendMode="normal"] - the default blend mode to use ("normal", "multiply")
|
|
39
|
+
* @param {boolean} [options.depthBuffer="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
39
40
|
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
|
|
40
41
|
* @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
|
|
41
42
|
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
@@ -70,6 +71,14 @@ import Point from '../geometries/point.js';
|
|
|
70
71
|
*/
|
|
71
72
|
this.isContextValid = true;
|
|
72
73
|
|
|
74
|
+
/**
|
|
75
|
+
* the default method to sort object ("sorting", "z-buffer")
|
|
76
|
+
* @type {string}
|
|
77
|
+
* @default "sorting"
|
|
78
|
+
*/
|
|
79
|
+
this.depthTest = "sorting";
|
|
80
|
+
|
|
81
|
+
|
|
73
82
|
/**
|
|
74
83
|
* The Path2D instance used by the renderer to draw primitives
|
|
75
84
|
* @type {Path2D}
|
|
@@ -200,7 +209,7 @@ import Point from '../geometries/point.js';
|
|
|
200
209
|
transparent = true;
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
|
|
212
|
+
let _context = canvas.getContext("2d", {
|
|
204
213
|
"alpha" : transparent
|
|
205
214
|
});
|
|
206
215
|
|
|
@@ -262,7 +271,7 @@ import Point from '../geometries/point.js';
|
|
|
262
271
|
* @param {number} height - new height of the canvas
|
|
263
272
|
*/
|
|
264
273
|
resize(width, height) {
|
|
265
|
-
|
|
274
|
+
let canvas = this.getCanvas();
|
|
266
275
|
if (width !== canvas.width || height !== canvas.height) {
|
|
267
276
|
canvas.width = width;
|
|
268
277
|
canvas.height = height;
|
|
@@ -281,7 +290,7 @@ import Point from '../geometries/point.js';
|
|
|
281
290
|
* @param {boolean} [enable=false]
|
|
282
291
|
*/
|
|
283
292
|
setAntiAlias(context, enable) {
|
|
284
|
-
|
|
293
|
+
let canvas = context.canvas;
|
|
285
294
|
|
|
286
295
|
// enable/disable antialis on the given Context2d object
|
|
287
296
|
setPrefixed("imageSmoothingEnabled", enable === true, context);
|
|
@@ -361,8 +370,8 @@ import Point from '../geometries/point.js';
|
|
|
361
370
|
* @returns {HTMLCanvasElement|OffscreenCanvas} a new canvas element representing the tinted image
|
|
362
371
|
*/
|
|
363
372
|
tint(src, color, mode) {
|
|
364
|
-
|
|
365
|
-
|
|
373
|
+
let canvas = createCanvas(src.width, src.height, true);
|
|
374
|
+
let context = this.getContext2d(canvas);
|
|
366
375
|
|
|
367
376
|
context.save();
|
|
368
377
|
|
|
@@ -414,6 +423,64 @@ import Point from '../geometries/point.js';
|
|
|
414
423
|
// reset to default
|
|
415
424
|
this.currentTint.setColor(255, 255, 255, 1.0);
|
|
416
425
|
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
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));
|
|
455
|
+
*/
|
|
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
|
+
}
|
|
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
|
+
}
|
|
417
484
|
}
|
|
418
485
|
|
|
419
486
|
export { Renderer as default };
|