melonjs 15.2.1 → 15.4.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 +1 -1
- package/dist/melonjs.mjs/_virtual/_commonjsHelpers.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 +1 -1
- package/dist/melonjs.mjs/application/application.js +75 -23
- package/dist/melonjs.mjs/application/header.js +2 -2
- package/dist/melonjs.mjs/application/resize.js +13 -11
- package/dist/melonjs.mjs/application/settings.js +37 -1
- package/dist/melonjs.mjs/audio/audio.js +4 -6
- package/dist/melonjs.mjs/camera/camera2d.js +12 -14
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +3 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +26 -59
- package/dist/melonjs.mjs/geometries/line.js +18 -25
- package/dist/melonjs.mjs/geometries/path2d.js +16 -13
- package/dist/melonjs.mjs/geometries/point.js +8 -16
- package/dist/melonjs.mjs/geometries/poly.js +40 -97
- package/dist/melonjs.mjs/geometries/rectangle.js +37 -91
- package/dist/melonjs.mjs/geometries/roundrect.js +26 -35
- package/dist/melonjs.mjs/index.js +6 -6
- package/dist/melonjs.mjs/input/gamepad.js +1 -1
- package/dist/melonjs.mjs/input/input.js +1 -1
- package/dist/melonjs.mjs/input/keyboard.js +3 -3
- package/dist/melonjs.mjs/input/pointer.js +4 -4
- package/dist/melonjs.mjs/input/pointerevent.js +6 -7
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +16 -33
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +3 -4
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +4 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +4 -7
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +37 -47
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +3 -3
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +2 -2
- 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 +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +1 -1
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +4 -5
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +5 -5
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +5 -59
- package/dist/melonjs.mjs/math/matrix3.js +82 -141
- package/dist/melonjs.mjs/math/observable_vector2.js +7 -7
- package/dist/melonjs.mjs/math/observable_vector3.js +5 -5
- package/dist/melonjs.mjs/math/vector2.js +7 -91
- package/dist/melonjs.mjs/math/vector3.js +6 -90
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- 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 +2 -2
- package/dist/melonjs.mjs/particles/particle.js +2 -2
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +22 -20
- package/dist/melonjs.mjs/physics/bounds.js +27 -33
- package/dist/melonjs.mjs/physics/collision.js +5 -5
- package/dist/melonjs.mjs/physics/detector.js +10 -10
- package/dist/melonjs.mjs/physics/quadtree.js +5 -5
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +3 -4
- package/dist/melonjs.mjs/physics/world.js +6 -9
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +4 -4
- package/dist/melonjs.mjs/renderable/container.js +25 -25
- package/dist/melonjs.mjs/renderable/draggable.js +1 -1
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +4 -4
- package/dist/melonjs.mjs/renderable/light2d.js +3 -3
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +2 -2
- package/dist/melonjs.mjs/renderable/renderable.js +31 -39
- package/dist/melonjs.mjs/renderable/sprite.js +3 -3
- package/dist/melonjs.mjs/renderable/text/bitmaptext.js +421 -0
- package/dist/melonjs.mjs/renderable/text/bitmaptextdata.js +195 -0
- package/dist/melonjs.mjs/renderable/text/glyph.js +65 -0
- package/dist/melonjs.mjs/renderable/text/text.js +422 -0
- package/dist/melonjs.mjs/renderable/text/textmetrics.js +175 -0
- package/dist/melonjs.mjs/renderable/text/textstyle.js +21 -0
- package/dist/melonjs.mjs/renderable/trigger.js +10 -10
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +7 -7
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +3 -3
- package/dist/melonjs.mjs/state/stage.js +13 -14
- package/dist/melonjs.mjs/state/state.js +4 -51
- package/dist/melonjs.mjs/system/device.js +51 -10
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +46 -2
- package/dist/melonjs.mjs/system/platform.js +18 -18
- package/dist/melonjs.mjs/system/pooling.js +10 -10
- package/dist/melonjs.mjs/system/save.js +1 -1
- package/dist/melonjs.mjs/system/timer.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptext.js +1 -1
- package/dist/melonjs.mjs/text/bitmaptextdata.js +3 -6
- package/dist/melonjs.mjs/text/glyph.js +1 -1
- package/dist/melonjs.mjs/text/text.js +1 -1
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +1 -1
- package/dist/melonjs.mjs/tweens/easing.js +1 -1
- package/dist/melonjs.mjs/tweens/interpolation.js +1 -1
- package/dist/melonjs.mjs/tweens/tween.js +2 -2
- package/dist/melonjs.mjs/utils/agent.js +1 -1
- package/dist/melonjs.mjs/utils/array.js +1 -1
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +2 -3
- package/dist/melonjs.mjs/utils/string.js +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +5 -18
- package/dist/melonjs.mjs/video/renderer.js +17 -30
- package/dist/melonjs.mjs/video/texture/atlas.js +13 -13
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +15 -15
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +5 -29
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +3 -3
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +13 -14
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +5 -5
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +2 -3
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -2
- 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 +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +4 -4
- package/dist/melonjs.mjs/video/webgl/utils/program.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +62 -67
- package/dist/melonjs.module.js +1272 -1713
- package/dist/types/application/application.d.ts +32 -31
- package/dist/types/application/header.d.ts +2 -2
- package/dist/types/application/settings.d.ts +80 -16
- package/dist/types/audio/audio.d.ts +4 -6
- package/dist/types/camera/camera2d.d.ts +13 -16
- package/dist/types/entity/entity.d.ts +0 -1
- package/dist/types/geometries/ellipse.d.ts +18 -50
- package/dist/types/geometries/path2d.d.ts +1 -1
- package/dist/types/geometries/point.d.ts +5 -13
- package/dist/types/geometries/poly.d.ts +26 -75
- package/dist/types/geometries/rectangle.d.ts +12 -58
- package/dist/types/geometries/roundrect.d.ts +2 -11
- package/dist/types/index.d.ts +3 -3
- package/dist/types/input/gamepad.d.ts +31 -31
- package/dist/types/input/keyboard.d.ts +105 -105
- package/dist/types/input/pointer.d.ts +21 -21
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/tiled/TMXLayer.d.ts +1 -1
- package/dist/types/level/tiled/TMXUtils.d.ts +4 -6
- package/dist/types/math/matrix2.d.ts +9 -63
- package/dist/types/math/matrix3.d.ts +9 -68
- package/dist/types/math/observable_vector2.d.ts +2 -2
- package/dist/types/math/observable_vector3.d.ts +2 -2
- package/dist/types/math/vector2.d.ts +8 -92
- package/dist/types/math/vector3.d.ts +8 -92
- package/dist/types/particles/settings.d.ts +29 -29
- package/dist/types/physics/body.d.ts +10 -8
- package/dist/types/physics/bounds.d.ts +24 -30
- package/dist/types/physics/collision.d.ts +12 -12
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/physics/world.d.ts +4 -7
- package/dist/types/renderable/container.d.ts +19 -19
- package/dist/types/renderable/imagelayer.d.ts +6 -6
- package/dist/types/renderable/light2d.d.ts +7 -7
- package/dist/types/renderable/renderable.d.ts +10 -18
- package/dist/types/renderable/text/bitmaptext.d.ts +151 -0
- package/dist/types/renderable/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/renderable/text/glyph.d.ts +28 -0
- package/dist/types/renderable/text/text.d.ts +159 -0
- package/dist/types/renderable/text/textmetrics.d.ts +47 -0
- package/dist/types/renderable/text/textstyle.d.ts +5 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +0 -1
- package/dist/types/renderable/ui/uispriteelement.d.ts +0 -1
- package/dist/types/renderable/ui/uitextbutton.d.ts +2 -7
- package/dist/types/state/stage.d.ts +3 -2
- package/dist/types/state/state.d.ts +11 -11
- package/dist/types/system/device.d.ts +16 -9
- package/dist/types/system/event.d.ts +40 -0
- package/dist/types/system/platform.d.ts +17 -17
- package/dist/types/utils/function.d.ts +1 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
- package/dist/types/video/renderer.d.ts +16 -43
- package/dist/types/video/texture/canvas_texture.d.ts +14 -14
- package/dist/types/video/video.d.ts +4 -38
- package/dist/types/video/webgl/buffer/vertex.d.ts +2 -2
- package/dist/types/video/webgl/compositors/compositor.d.ts +24 -13
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +0 -1
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +0 -1
- package/dist/types/video/webgl/utils/precision.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +48 -84
- package/package.json +15 -15
- package/src/application/application.js +73 -21
- package/src/application/header.js +1 -1
- package/src/application/resize.js +11 -9
- package/src/application/settings.js +36 -0
- package/src/audio/audio.js +3 -5
- package/src/camera/camera2d.js +11 -13
- package/src/entity/entity.js +2 -3
- package/src/geometries/ellipse.js +25 -58
- package/src/geometries/line.js +17 -24
- package/src/geometries/path2d.js +15 -12
- package/src/geometries/point.js +7 -15
- package/src/geometries/poly.js +39 -96
- package/src/geometries/rectangle.js +36 -90
- package/src/geometries/roundrect.js +25 -34
- package/src/index.js +4 -4
- package/src/input/keyboard.js +2 -2
- package/src/input/pointer.js +3 -3
- package/src/input/pointerevent.js +5 -6
- package/src/lang/deprecated.js +1 -1
- package/src/level/tiled/TMXLayer.js +15 -32
- package/src/level/tiled/TMXObject.js +2 -3
- package/src/level/tiled/TMXTile.js +3 -3
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/level/tiled/TMXTileset.js +3 -6
- package/src/level/tiled/TMXTilesetGroup.js +1 -1
- package/src/level/tiled/TMXUtils.js +36 -46
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -2
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/parser.js +3 -4
- package/src/math/color.js +4 -4
- package/src/math/matrix2.js +4 -58
- package/src/math/matrix3.js +81 -140
- package/src/math/observable_vector2.js +6 -6
- package/src/math/observable_vector3.js +4 -4
- package/src/math/vector2.js +6 -90
- package/src/math/vector3.js +5 -89
- package/src/particles/emitter.js +1 -1
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +21 -19
- package/src/physics/bounds.js +26 -32
- package/src/physics/collision.js +4 -4
- package/src/physics/detector.js +9 -9
- package/src/physics/quadtree.js +4 -4
- package/src/physics/sat.js +2 -3
- package/src/physics/world.js +5 -8
- package/src/polyfill/roundrect.js +163 -163
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/colorlayer.js +3 -3
- package/src/renderable/container.js +24 -24
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/light2d.js +2 -2
- package/src/renderable/nineslicesprite.js +1 -1
- package/src/renderable/renderable.js +30 -38
- package/src/renderable/sprite.js +2 -2
- package/src/{text → renderable/text}/bitmaptext.js +8 -8
- package/src/{text → renderable/text}/bitmaptextdata.js +4 -7
- package/src/{text → renderable/text}/glyph.js +1 -1
- package/src/{text → renderable/text}/text.js +16 -17
- package/src/{text → renderable/text}/textmetrics.js +2 -2
- package/src/renderable/trigger.js +9 -9
- package/src/renderable/ui/uibaseelement.js +6 -6
- package/src/renderable/ui/uispriteelement.js +6 -6
- package/src/renderable/ui/uitextbutton.js +2 -2
- package/src/state/stage.js +12 -13
- package/src/state/state.js +2 -61
- package/src/system/device.js +50 -9
- package/src/system/event.js +44 -0
- package/src/system/platform.js +18 -18
- package/src/system/pooling.js +9 -9
- package/src/tweens/tween.js +1 -1
- package/src/utils/function.js +1 -2
- package/src/video/canvas/canvas_renderer.js +4 -17
- package/src/video/renderer.js +16 -29
- package/src/video/texture/atlas.js +12 -12
- package/src/video/texture/canvas_texture.js +14 -14
- package/src/video/video.js +7 -28
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/compositors/compositor.js +12 -13
- package/src/video/webgl/compositors/primitive_compositor.js +4 -4
- package/src/video/webgl/compositors/quad_compositor.js +1 -2
- package/src/video/webgl/glshader.js +1 -1
- package/src/video/webgl/utils/precision.js +3 -3
- package/src/video/webgl/webgl_renderer.js +61 -66
- /package/src/{text → renderable/text}/textstyle.js +0 -0
|
@@ -28,7 +28,6 @@ export default class QuadCompositor extends Compositor {
|
|
|
28
28
|
/**
|
|
29
29
|
* delete the given WebGL texture
|
|
30
30
|
* @param {WebGLTexture} [texture] - a WebGL texture to delete
|
|
31
|
-
* @param {number} [unit] - Texture unit to delete
|
|
32
31
|
*/
|
|
33
32
|
deleteTexture2D(texture?: WebGLTexture | undefined): void;
|
|
34
33
|
/**
|
|
@@ -7,7 +7,7 @@ export function setPrecision(src: any, precision: any): any;
|
|
|
7
7
|
/**
|
|
8
8
|
* return the highest precision format supported by this device for GL Shaders
|
|
9
9
|
* @ignore
|
|
10
|
-
* @param {WebGLRenderingContext} gl
|
|
10
|
+
* @param {WebGLRenderingContext} gl - the current WebGL context
|
|
11
11
|
* @returns {boolean} "lowp", "mediump", or "highp"
|
|
12
12
|
*/
|
|
13
13
|
export function getMaxShaderPrecision(gl: WebGLRenderingContext): boolean;
|
|
@@ -4,39 +4,6 @@
|
|
|
4
4
|
* @augments Renderer
|
|
5
5
|
*/
|
|
6
6
|
export default class WebGLRenderer extends Renderer {
|
|
7
|
-
/**
|
|
8
|
-
* @param {object} options - The renderer parameters
|
|
9
|
-
* @param {number} options.width - The width of the canvas without scaling
|
|
10
|
-
* @param {number} options.height - The height of the canvas without scaling
|
|
11
|
-
* @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
|
|
12
|
-
* @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing
|
|
13
|
-
* @param {boolean} [options.failIfMajorPerformanceCaveat=true] - If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
|
|
14
|
-
* @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
|
|
15
|
-
* @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
|
|
16
|
-
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
|
|
17
|
-
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
18
|
-
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
19
|
-
* @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
20
|
-
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
21
|
-
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
22
|
-
* @param {Compositor} [options.compositor] - A class that implements the compositor API for sprite rendering
|
|
23
|
-
*/
|
|
24
|
-
constructor(options: {
|
|
25
|
-
width: number;
|
|
26
|
-
height: number;
|
|
27
|
-
canvas?: HTMLCanvasElement | undefined;
|
|
28
|
-
antiAlias?: boolean | undefined;
|
|
29
|
-
failIfMajorPerformanceCaveat?: boolean | undefined;
|
|
30
|
-
transparent?: boolean | undefined;
|
|
31
|
-
premultipliedAlpha?: boolean | undefined;
|
|
32
|
-
subPixel?: boolean | undefined;
|
|
33
|
-
preferWebGL1?: boolean | undefined;
|
|
34
|
-
depthTest?: boolean | undefined;
|
|
35
|
-
powerPreference?: string | undefined;
|
|
36
|
-
zoomX?: number | undefined;
|
|
37
|
-
zoomY?: number | undefined;
|
|
38
|
-
compositor?: any;
|
|
39
|
-
});
|
|
40
7
|
/**
|
|
41
8
|
* The WebGL version used by this renderer (1 or 2)
|
|
42
9
|
* @type {number}
|
|
@@ -112,21 +79,21 @@ export default class WebGLRenderer extends Renderer {
|
|
|
112
79
|
* @type {Map<WebGLCompositor>}
|
|
113
80
|
*/
|
|
114
81
|
compositors: Map<WebGLCompositor, any>;
|
|
115
|
-
depthTest:
|
|
82
|
+
depthTest: any;
|
|
116
83
|
customShader: any;
|
|
117
84
|
cache: TextureCache;
|
|
118
85
|
/**
|
|
119
86
|
* add a new compositor to this renderer
|
|
120
87
|
* @param {Compositor} compositor - a compositor instance
|
|
121
|
-
* @param {
|
|
122
|
-
* @param {
|
|
88
|
+
* @param {string} name - a name uniquely identifying this compositor
|
|
89
|
+
* @param {boolean} [activate=false] - true if the given compositor should be set as the active one
|
|
123
90
|
*/
|
|
124
91
|
addCompositor(compositor: Compositor, name?: string, activate?: boolean | undefined): void;
|
|
125
92
|
/**
|
|
126
93
|
* set the active compositor for this renderer
|
|
127
|
-
* @param {
|
|
94
|
+
* @param {string} name - a compositor name
|
|
128
95
|
* @param {GLShader} [shader] - an optional shader program to be used, instead of the default one, when activating the compositor
|
|
129
|
-
* @
|
|
96
|
+
* @returns {Compositor} an instance to the current active compositor
|
|
130
97
|
*/
|
|
131
98
|
setCompositor(name?: string, shader?: any): Compositor;
|
|
132
99
|
/**
|
|
@@ -137,7 +104,7 @@ export default class WebGLRenderer extends Renderer {
|
|
|
137
104
|
* Create a pattern with the specified repetition
|
|
138
105
|
* @param {HTMLImageElement|SVGImageElement|HTMLVideoElement|HTMLCanvasElement|ImageBitmap|OffscreenCanvas|VideoFrame} image - Source image to be used as the pattern's image
|
|
139
106
|
* @param {string} repeat - Define how the pattern should be repeated
|
|
140
|
-
* @returns {TextureAtlas}
|
|
107
|
+
* @returns {TextureAtlas} the patterned texture created
|
|
141
108
|
* @see ImageLayer#repeat
|
|
142
109
|
* @example
|
|
143
110
|
* let tileable = renderer.createPattern(image, "repeat");
|
|
@@ -148,7 +115,7 @@ export default class WebGLRenderer extends Renderer {
|
|
|
148
115
|
createPattern(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | VideoFrame, repeat: string): TextureAtlas;
|
|
149
116
|
/**
|
|
150
117
|
* set/change the current projection matrix (WebGL only)
|
|
151
|
-
* @param {Matrix3d} matrix
|
|
118
|
+
* @param {Matrix3d} matrix - the new projection matrix
|
|
152
119
|
*/
|
|
153
120
|
setProjection(matrix: Matrix3d): void;
|
|
154
121
|
/**
|
|
@@ -196,25 +163,25 @@ export default class WebGLRenderer extends Renderer {
|
|
|
196
163
|
/**
|
|
197
164
|
* Draw a pattern within the given rectangle.
|
|
198
165
|
* @param {TextureAtlas} pattern - Pattern object
|
|
199
|
-
* @param {number} x
|
|
200
|
-
* @param {number} y
|
|
201
|
-
* @param {number} width
|
|
202
|
-
* @param {number} height
|
|
166
|
+
* @param {number} x - x position where to draw the pattern
|
|
167
|
+
* @param {number} y - y position where to draw the pattern
|
|
168
|
+
* @param {number} width - width of the pattern
|
|
169
|
+
* @param {number} height - height of the pattern
|
|
203
170
|
* @see WebGLRenderer#createPattern
|
|
204
171
|
*/
|
|
205
172
|
drawPattern(pattern: TextureAtlas, x: number, y: number, width: number, height: number): void;
|
|
206
173
|
/**
|
|
207
174
|
* Returns the WebGL Context object of the given canvas element
|
|
208
|
-
* @param {HTMLCanvasElement} canvas
|
|
175
|
+
* @param {HTMLCanvasElement} canvas - the canvas element
|
|
209
176
|
* @param {boolean} [transparent=false] - use true to enable transparency
|
|
210
177
|
* @param {boolean} [depth=false] - use true to enable depth buffer testing
|
|
211
|
-
* @returns {WebGLRenderingContext}
|
|
178
|
+
* @returns {WebGLRenderingContext} the WebGL Context object
|
|
212
179
|
*/
|
|
213
180
|
getContextGL(canvas: HTMLCanvasElement, transparent?: boolean | undefined, depth?: boolean | undefined): WebGLRenderingContext;
|
|
214
181
|
/**
|
|
215
182
|
* Returns the WebGLContext instance for the renderer
|
|
216
183
|
* return a reference to the system 2d Context
|
|
217
|
-
* @returns {WebGLRenderingContext}
|
|
184
|
+
* @returns {WebGLRenderingContext} the current WebGL context
|
|
218
185
|
*/
|
|
219
186
|
getContext(): WebGLRenderingContext;
|
|
220
187
|
/**
|
|
@@ -230,10 +197,9 @@ export default class WebGLRenderer extends Renderer {
|
|
|
230
197
|
* <img src="images/screen-blendmode.png" width="510"/> <br>
|
|
231
198
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation
|
|
232
199
|
* @param {string} [mode="normal"] - blend mode : "normal", "multiply", "lighter", "additive", "screen"
|
|
233
|
-
* @param {WebGLRenderingContext} [gl]
|
|
200
|
+
* @param {WebGLRenderingContext} [gl] - a WebGL context
|
|
234
201
|
*/
|
|
235
202
|
setBlendMode(mode?: string | undefined, gl?: WebGLRenderingContext | undefined): void;
|
|
236
|
-
currentBlendMode: any;
|
|
237
203
|
/**
|
|
238
204
|
* restores the canvas context
|
|
239
205
|
*/
|
|
@@ -249,8 +215,8 @@ export default class WebGLRenderer extends Renderer {
|
|
|
249
215
|
rotate(angle: number): void;
|
|
250
216
|
/**
|
|
251
217
|
* scales the uniform matrix
|
|
252
|
-
* @param {number} x
|
|
253
|
-
* @param {number} y
|
|
218
|
+
* @param {number} x - x-axis scale
|
|
219
|
+
* @param {number} y - y-axis scale
|
|
254
220
|
*/
|
|
255
221
|
scale(x: number, y: number): void;
|
|
256
222
|
/**
|
|
@@ -283,18 +249,18 @@ export default class WebGLRenderer extends Renderer {
|
|
|
283
249
|
* Stroke an arc at the specified coordinates with given radius, start and end points
|
|
284
250
|
* @param {number} x - arc center point x-axis
|
|
285
251
|
* @param {number} y - arc center point y-axis
|
|
286
|
-
* @param {number} radius
|
|
252
|
+
* @param {number} radius - arc radius
|
|
287
253
|
* @param {number} start - start angle in radians
|
|
288
254
|
* @param {number} end - end angle in radians
|
|
289
255
|
* @param {boolean} [antiClockwise=false] - draw arc anti-clockwise
|
|
290
|
-
* @param {boolean} [fill=false]
|
|
256
|
+
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
291
257
|
*/
|
|
292
258
|
strokeArc(x: number, y: number, radius: number, start: number, end: number, antiClockwise?: boolean | undefined, fill?: boolean | undefined): void;
|
|
293
259
|
/**
|
|
294
260
|
* Fill an arc at the specified coordinates with given radius, start and end points
|
|
295
261
|
* @param {number} x - arc center point x-axis
|
|
296
262
|
* @param {number} y - arc center point y-axis
|
|
297
|
-
* @param {number} radius
|
|
263
|
+
* @param {number} radius - arc radius
|
|
298
264
|
* @param {number} start - start angle in radians
|
|
299
265
|
* @param {number} end - end angle in radians
|
|
300
266
|
* @param {boolean} [antiClockwise=false] - draw arc anti-clockwise
|
|
@@ -346,52 +312,50 @@ export default class WebGLRenderer extends Renderer {
|
|
|
346
312
|
fillPolygon(poly: Polygon): void;
|
|
347
313
|
/**
|
|
348
314
|
* Draw a stroke rectangle at the specified coordinates
|
|
349
|
-
* @param {number} x
|
|
350
|
-
* @param {number} y
|
|
351
|
-
* @param {number} width
|
|
352
|
-
* @param {number} height
|
|
315
|
+
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
316
|
+
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
317
|
+
* @param {number} width - The rectangle's width.
|
|
318
|
+
* @param {number} height - The rectangle's height.
|
|
353
319
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
354
320
|
*/
|
|
355
321
|
strokeRect(x: number, y: number, width: number, height: number, fill?: boolean | undefined): void;
|
|
356
322
|
/**
|
|
357
323
|
* Draw a filled rectangle at the specified coordinates
|
|
358
|
-
* @param {number} x
|
|
359
|
-
* @param {number} y
|
|
360
|
-
* @param {number} width
|
|
361
|
-
* @param {number} height
|
|
324
|
+
* @param {number} x - x axis of the coordinate for the rectangle starting point.
|
|
325
|
+
* @param {number} y - y axis of the coordinate for the rectangle starting point.
|
|
326
|
+
* @param {number} width - The rectangle's width.
|
|
327
|
+
* @param {number} height - The rectangle's height.
|
|
362
328
|
*/
|
|
363
329
|
fillRect(x: number, y: number, width: number, height: number): void;
|
|
364
330
|
/**
|
|
365
331
|
* Stroke a rounded rectangle at the specified coordinates
|
|
366
|
-
* @param {number} x
|
|
367
|
-
* @param {number} y
|
|
368
|
-
* @param {number} width
|
|
369
|
-
* @param {number} height
|
|
370
|
-
* @param {number} radius
|
|
332
|
+
* @param {number} x - x axis of the coordinate for the rounded rectangle starting point.
|
|
333
|
+
* @param {number} y - y axis of the coordinate for the rounded rectangle starting point.
|
|
334
|
+
* @param {number} width - The rounded rectangle's width.
|
|
335
|
+
* @param {number} height - The rounded rectangle's height.
|
|
336
|
+
* @param {number} radius - The rounded corner's radius.
|
|
371
337
|
* @param {boolean} [fill=false] - also fill the shape with the current color if true
|
|
372
338
|
*/
|
|
373
339
|
strokeRoundRect(x: number, y: number, width: number, height: number, radius: number, fill?: boolean | undefined): void;
|
|
374
340
|
/**
|
|
375
341
|
* Draw a rounded filled rectangle at the specified coordinates
|
|
376
|
-
* @param {number} x
|
|
377
|
-
* @param {number} y
|
|
378
|
-
* @param {number} width
|
|
379
|
-
* @param {number} height
|
|
380
|
-
* @param {number} radius
|
|
342
|
+
* @param {number} x - x axis of the coordinate for the rounded rectangle starting point.
|
|
343
|
+
* @param {number} y - y axis of the coordinate for the rounded rectangle starting point.
|
|
344
|
+
* @param {number} width - The rounded rectangle's width.
|
|
345
|
+
* @param {number} height - The rounded rectangle's height.
|
|
346
|
+
* @param {number} radius - The rounded corner's radius.
|
|
381
347
|
*/
|
|
382
348
|
fillRoundRect(x: number, y: number, width: number, height: number, radius: number): void;
|
|
383
349
|
/**
|
|
384
350
|
* Stroke a Point at the specified coordinates
|
|
385
|
-
* @param {number} x
|
|
386
|
-
* @param {number} y
|
|
351
|
+
* @param {number} x - x axis of the coordinate for the point.
|
|
352
|
+
* @param {number} y - y axis of the coordinate for the point.
|
|
387
353
|
*/
|
|
388
354
|
strokePoint(x: number, y: number): void;
|
|
389
355
|
/**
|
|
390
356
|
* Draw a a point at the specified coordinates
|
|
391
|
-
* @param {number} x
|
|
392
|
-
* @param {number} y
|
|
393
|
-
* @param {number} width
|
|
394
|
-
* @param {number} height
|
|
357
|
+
* @param {number} x - x axis of the coordinate for the point.
|
|
358
|
+
* @param {number} y - y axis of the coordinate for the point.
|
|
395
359
|
*/
|
|
396
360
|
fillPoint(x: number, y: number): void;
|
|
397
361
|
/**
|
|
@@ -407,8 +371,8 @@ export default class WebGLRenderer extends Renderer {
|
|
|
407
371
|
transform(mat2d: Matrix2d): void;
|
|
408
372
|
/**
|
|
409
373
|
* Translates the uniform matrix by the given coordinates
|
|
410
|
-
* @param {number} x
|
|
411
|
-
* @param {number} y
|
|
374
|
+
* @param {number} x - x axis of the coordinate for the translation.
|
|
375
|
+
* @param {number} y - y axis of the coordinate for the translation.
|
|
412
376
|
*/
|
|
413
377
|
translate(x: number, y: number): void;
|
|
414
378
|
/**
|
|
@@ -417,10 +381,10 @@ export default class WebGLRenderer extends Renderer {
|
|
|
417
381
|
* You can however save the current region using the save(),
|
|
418
382
|
* and restore it (with the restore() method) any time in the future.
|
|
419
383
|
* (<u>this is an experimental feature !</u>)
|
|
420
|
-
* @param {number} x
|
|
421
|
-
* @param {number} y
|
|
422
|
-
* @param {number} width
|
|
423
|
-
* @param {number} height
|
|
384
|
+
* @param {number} x - x axis of the coordinate for the upper-left corner of the rectangle to start clipping from.
|
|
385
|
+
* @param {number} y - y axis of the coordinate for the upper-left corner of the rectangle to start clipping from.
|
|
386
|
+
* @param {number} width - the width of the rectangle to start clipping from.
|
|
387
|
+
* @param {number} height - the height of the rectangle to start clipping from.
|
|
424
388
|
*/
|
|
425
389
|
clipRect(x: number, y: number, width: number, height: number): void;
|
|
426
390
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.4.0",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"type": "module",
|
|
@@ -53,37 +53,37 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@teppeis/multimaps": "^3.0.0",
|
|
56
|
-
"core-js": "^3.
|
|
56
|
+
"core-js": "^3.31.0",
|
|
57
57
|
"earcut": "2.2.4",
|
|
58
58
|
"eventemitter3": "^5.0.1",
|
|
59
59
|
"howler": "2.2.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@babel/eslint-parser": "^7.
|
|
63
|
-
"@babel/plugin-syntax-import-assertions": "^7.
|
|
64
|
-
"@fastify/static": "^6.10.
|
|
62
|
+
"@babel/eslint-parser": "^7.22.5",
|
|
63
|
+
"@babel/plugin-syntax-import-assertions": "^7.22.5",
|
|
64
|
+
"@fastify/static": "^6.10.2",
|
|
65
65
|
"@melonjs/webdoc-theme": "^1.1.1",
|
|
66
|
-
"@rollup/plugin-commonjs": "^25.0.
|
|
66
|
+
"@rollup/plugin-commonjs": "^25.0.2",
|
|
67
67
|
"@rollup/plugin-image": "^3.0.2",
|
|
68
|
-
"@rollup/plugin-node-resolve": "^15.0
|
|
68
|
+
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
69
69
|
"@rollup/plugin-replace": "^5.0.2",
|
|
70
70
|
"@webdoc/cli": "^2.2.0",
|
|
71
|
-
"chromedriver": "^
|
|
71
|
+
"chromedriver": "^114.0.2",
|
|
72
72
|
"cross-env": "^7.0.3",
|
|
73
73
|
"del-cli": "^5.0.0",
|
|
74
|
-
"eslint": "^8.
|
|
75
|
-
"eslint-plugin-jsdoc": "^
|
|
74
|
+
"eslint": "^8.43.0",
|
|
75
|
+
"eslint-plugin-jsdoc": "^46.2.6",
|
|
76
76
|
"expect": "^29.5.0",
|
|
77
77
|
"expect-mocha-image-snapshot": "^3.0.13",
|
|
78
|
-
"fastify": "^4.
|
|
78
|
+
"fastify": "^4.18.0",
|
|
79
79
|
"mocha": "^10.2.0",
|
|
80
80
|
"npm-self-link": "^1.1.7",
|
|
81
|
-
"puppeteer": "^20.
|
|
82
|
-
"rollup": "^3.
|
|
81
|
+
"puppeteer": "^20.7.3",
|
|
82
|
+
"rollup": "^3.25.1",
|
|
83
83
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
84
84
|
"rollup-plugin-string": "^3.0.0",
|
|
85
|
-
"terser": "^5.
|
|
86
|
-
"typescript": "^5.
|
|
85
|
+
"terser": "^5.18.1",
|
|
86
|
+
"typescript": "^5.1.3"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"build": "npm run lint && rollup -c --silent",
|
|
@@ -17,21 +17,11 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
17
17
|
* An Application is responsible for updating (each frame) all the related object status and draw them.
|
|
18
18
|
* @see game
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
export default class Application {
|
|
21
21
|
/**
|
|
22
22
|
* @param {number} width - The width of the canvas viewport
|
|
23
23
|
* @param {number} height - The height of the canvas viewport
|
|
24
|
-
* @param {
|
|
25
|
-
* @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
|
|
26
|
-
* @param {number|Renderer} [options.renderer=AUTO] - renderer to use (CANVAS, WEBGL, AUTO), or a custom renderer class
|
|
27
|
-
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
28
|
-
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
29
|
-
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
30
|
-
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
31
|
-
* @param {string} [options.powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context ("default", "high-performance", "low-power"). To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
32
|
-
* @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
33
|
-
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
|
|
34
|
-
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
24
|
+
* @param {Application.Settings} [options] - The optional parameters for the application and default renderer
|
|
35
25
|
* @throws Will throw an exception if it fails to instantiate a renderer
|
|
36
26
|
* @example
|
|
37
27
|
* let my game = new Application(640, 480, {renderer: me.video.AUTO}) {
|
|
@@ -91,10 +81,34 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
91
81
|
|
|
92
82
|
/**
|
|
93
83
|
* the given settings used when creating this application
|
|
94
|
-
* @type {
|
|
84
|
+
* @type {object}
|
|
95
85
|
*/
|
|
96
86
|
this.settings = undefined;
|
|
97
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Specify whether to pause this app when losing focus
|
|
90
|
+
* @type {boolean}
|
|
91
|
+
* @default true
|
|
92
|
+
* @example
|
|
93
|
+
* // keep the default game instance running even when loosing focus
|
|
94
|
+
* me.game.pauseOnBlur = false;
|
|
95
|
+
*/
|
|
96
|
+
this.pauseOnBlur = true;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Specify whether to unpause this app when gaining back focus
|
|
100
|
+
* @type {boolean}
|
|
101
|
+
* @default true
|
|
102
|
+
*/
|
|
103
|
+
this.resumeOnFocus = true;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Specify whether to stop this app when losing focus
|
|
107
|
+
* @type {boolean}
|
|
108
|
+
* @default false
|
|
109
|
+
*/
|
|
110
|
+
this.stopOnBlur = false;
|
|
111
|
+
|
|
98
112
|
// to know when we have to refresh the display
|
|
99
113
|
this.isDirty = true;
|
|
100
114
|
|
|
@@ -126,6 +140,9 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
126
140
|
|
|
127
141
|
/**
|
|
128
142
|
* init the game instance (create a physic world, update starting time, etc..)
|
|
143
|
+
* @param {number} width - The width of the canvas viewport
|
|
144
|
+
* @param {number} height - The height of the canvas viewport
|
|
145
|
+
* @param {Application.Settings} [options] - The optional parameters for the application and default renderer
|
|
129
146
|
*/
|
|
130
147
|
init(width, height, options) {
|
|
131
148
|
|
|
@@ -166,6 +183,12 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
166
183
|
this.settings.zoomX = width * this.settings.scale;
|
|
167
184
|
this.settings.zoomY = height * this.settings.scale;
|
|
168
185
|
|
|
186
|
+
// identify parent element and/or the html target for resizing
|
|
187
|
+
this.parentElement = device.getElement(this.settings.parent);
|
|
188
|
+
if (typeof this.settings.scaleTarget !== "undefined" ) {
|
|
189
|
+
this.settings.scaleTarget = device.getElement(this.settings.scaleTarget);
|
|
190
|
+
}
|
|
191
|
+
|
|
169
192
|
if (typeof this.settings.renderer === "number") {
|
|
170
193
|
switch (this.settings.renderer) {
|
|
171
194
|
case AUTO:
|
|
@@ -187,7 +210,6 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
187
210
|
event.on(event.WINDOW_ONORIENTATION_CHANGE, () => onresize(this), this);
|
|
188
211
|
|
|
189
212
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
190
|
-
this.parentElement = device.getElement(this.settings.parent);
|
|
191
213
|
this.parentElement.appendChild(this.renderer.getCanvas());
|
|
192
214
|
|
|
193
215
|
// Mobile browser hacks
|
|
@@ -226,6 +248,37 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
226
248
|
this.isInitialized = true;
|
|
227
249
|
|
|
228
250
|
event.emit(event.GAME_INIT, this);
|
|
251
|
+
event.on(event.STATE_CHANGE, this.repaint, this);
|
|
252
|
+
event.on(event.STATE_RESTART, this.repaint, this);
|
|
253
|
+
event.on(event.STATE_RESUME, this.repaint, this);
|
|
254
|
+
event.on(event.STAGE_RESET, this.reset, this);
|
|
255
|
+
event.on(event.TICK, (time) => {
|
|
256
|
+
// update all game objects
|
|
257
|
+
this.update(time);
|
|
258
|
+
// render all game objects
|
|
259
|
+
this.draw();
|
|
260
|
+
}, this);
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
// on blur event, pause the current
|
|
264
|
+
event.on(event.BLUR, () => {
|
|
265
|
+
if (this.stopOnBlur === true) {
|
|
266
|
+
state.stop(true);
|
|
267
|
+
}
|
|
268
|
+
if (this.pauseOnBlur === true) {
|
|
269
|
+
state.pause(true);
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// on focus event, restart or resume the current
|
|
274
|
+
event.on(event.FOCUS, () => {
|
|
275
|
+
if (this.stopOnBlur === true) {
|
|
276
|
+
state.restart(true);
|
|
277
|
+
}
|
|
278
|
+
if (this.resumeOnFocus === true) {
|
|
279
|
+
state.resume(true);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
229
282
|
}
|
|
230
283
|
|
|
231
284
|
/**
|
|
@@ -290,7 +343,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
290
343
|
|
|
291
344
|
/**
|
|
292
345
|
* Returns the parent HTML Element holding the main canvas of this application
|
|
293
|
-
* @returns {HTMLElement}
|
|
346
|
+
* @returns {HTMLElement} the parent HTML element
|
|
294
347
|
*/
|
|
295
348
|
getParentElement() {
|
|
296
349
|
return this.parentElement;
|
|
@@ -306,9 +359,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
306
359
|
/**
|
|
307
360
|
* update all objects related to this game active scene/stage
|
|
308
361
|
* @param {number} time - current timestamp as provided by the RAF callback
|
|
309
|
-
* @param {Stage} stage - the current stage
|
|
310
362
|
*/
|
|
311
|
-
update(time
|
|
363
|
+
update(time) {
|
|
312
364
|
// handle frame skipping if required
|
|
313
365
|
if ((++this.frameCounter % this.frameRate) === 0) {
|
|
314
366
|
// reset the frame counter
|
|
@@ -332,7 +384,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
332
384
|
}
|
|
333
385
|
|
|
334
386
|
// update all objects (and pass the elapsed time since last frame)
|
|
335
|
-
this.isDirty =
|
|
387
|
+
this.isDirty = this.world.update(this.updateDelta);
|
|
388
|
+
this.isDirty = state.current().update(this.updateDelta) || this.isDirty;
|
|
336
389
|
|
|
337
390
|
this.lastUpdate = globalThis.performance.now();
|
|
338
391
|
this.updateAverageDelta = this.lastUpdate - this.lastUpdateStart;
|
|
@@ -351,9 +404,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
351
404
|
|
|
352
405
|
/**
|
|
353
406
|
* draw the active scene/stage associated to this game
|
|
354
|
-
* @param {Stage} stage - the current stage
|
|
355
407
|
*/
|
|
356
|
-
draw(
|
|
408
|
+
draw() {
|
|
357
409
|
if (this.renderer.isContextValid === true && (this.isDirty || this.isAlwaysDirty)) {
|
|
358
410
|
// publish notification
|
|
359
411
|
event.emit(event.GAME_BEFORE_DRAW, globalThis.performance.now());
|
|
@@ -362,7 +414,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
362
414
|
this.renderer.clear();
|
|
363
415
|
|
|
364
416
|
// render the stage
|
|
365
|
-
|
|
417
|
+
state.current().draw(this.renderer, this.world);
|
|
366
418
|
|
|
367
419
|
// set back to flag
|
|
368
420
|
this.isDirty = false;
|
|
@@ -2,7 +2,7 @@ import * as device from "../system/device";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* display information
|
|
5
|
-
* @param {Application}
|
|
5
|
+
* @param {Application} app - the game application instance calling this function
|
|
6
6
|
*/
|
|
7
7
|
export function consoleHeader(app) {
|
|
8
8
|
let renderType = app.renderer.type;
|
|
@@ -42,7 +42,8 @@ function scale(game, x, y) {
|
|
|
42
42
|
export function onresize(game) {
|
|
43
43
|
let renderer = game.renderer;
|
|
44
44
|
let settings = renderer.settings;
|
|
45
|
-
let scaleX =
|
|
45
|
+
let scaleX = settings.scale, scaleY = settings.scale;
|
|
46
|
+
let nodeBounds;
|
|
46
47
|
|
|
47
48
|
if (settings.autoScale) {
|
|
48
49
|
|
|
@@ -56,8 +57,13 @@ export function onresize(game) {
|
|
|
56
57
|
canvasMaxHeight = parseInt(style.maxHeight, 10) || Infinity;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
if (typeof game.settings.scaleTarget !== "undefined") {
|
|
61
|
+
// get the bounds of the given scale target
|
|
62
|
+
nodeBounds = device.getElementBounds(game.settings.scaleTarget);
|
|
63
|
+
} else {
|
|
64
|
+
// get the maximum canvas size within the parent div containing the canvas container
|
|
65
|
+
nodeBounds = device.getParentBounds(game.getParentElement());
|
|
66
|
+
}
|
|
61
67
|
|
|
62
68
|
let _max_width = Math.min(canvasMaxWidth, nodeBounds.width);
|
|
63
69
|
let _max_height = Math.min(canvasMaxHeight, nodeBounds.height);
|
|
@@ -102,11 +108,7 @@ export function onresize(game) {
|
|
|
102
108
|
scaleX = scaleY = _max_height / settings.height;
|
|
103
109
|
}
|
|
104
110
|
}
|
|
105
|
-
|
|
106
|
-
// adjust scaling ratio based on the new scaling ratio
|
|
107
|
-
scale(game, scaleX, scaleY);
|
|
108
|
-
} else {
|
|
109
|
-
// adjust scaling ratio based on the given settings
|
|
110
|
-
scale(game, settings.scale, settings.scale);
|
|
111
111
|
}
|
|
112
|
+
// adjust scaling ratio
|
|
113
|
+
scale(game, scaleX, scaleY);
|
|
112
114
|
}
|
|
@@ -5,6 +5,7 @@ export const defaultSettings = {
|
|
|
5
5
|
autoScale : false,
|
|
6
6
|
scale : 1.0,
|
|
7
7
|
scaleMethod : "manual",
|
|
8
|
+
scaleTarget : undefined,
|
|
8
9
|
transparent : false,
|
|
9
10
|
premultipliedAlpha: true,
|
|
10
11
|
blendMode : "normal",
|
|
@@ -17,3 +18,38 @@ export const defaultSettings = {
|
|
|
17
18
|
consoleHeader : true,
|
|
18
19
|
legacy : false
|
|
19
20
|
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Application & Renderer Settings definition.
|
|
24
|
+
* @typedef {object} Settings
|
|
25
|
+
* @property {string|HTMLElement} [parent=document.body] - the DOM parent element to hold the canvas in the HTML file
|
|
26
|
+
* @property {number|Renderer} [renderer=AUTO] - renderer to use (CANVAS, WEBGL, AUTO), or a custom renderer class
|
|
27
|
+
* @property {number|string} [scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
28
|
+
* @property {"fit"|"fill-min"|"fill-max"|"flex"|"flex-width"|"flex-height"|"stretch"} [scaleMethod="fit"] - screen scaling modes : <br>
|
|
29
|
+
* - <i><b>`fit`</b></i> : Letterboxed; content is scaled to design aspect ratio <br>
|
|
30
|
+
* <center><img src="images/scale-fit.png"/></center><br>
|
|
31
|
+
* - <i><b>`fill-min`</b></i> : Canvas is resized to fit minimum design resolution; content is scaled to design aspect ratio <br>
|
|
32
|
+
* <center><img src="images/scale-fill-min.png"/></center><br>
|
|
33
|
+
* - <i><b>`fill-max`</b></i> : Canvas is resized to fit maximum design resolution; content is scaled to design aspect ratio <br>
|
|
34
|
+
* <center><img src="images/scale-fill-max.png"/></center><br>
|
|
35
|
+
* - <i><b>`flex`</b><</i> : Canvas width & height is resized to fit; content is scaled to design aspect ratio <br>
|
|
36
|
+
* <center><img src="images/scale-flex.png"/></center><br>
|
|
37
|
+
* - <i><b>`flex-width`</b></i> : Canvas width is resized to fit; content is scaled to design aspect ratio <br>
|
|
38
|
+
* <center><img src="images/scale-flex-width.png"/></center><br>
|
|
39
|
+
* - <i><b>`flex-height`</b></i> : Canvas height is resized to fit; content is scaled to design aspect ratio <br>
|
|
40
|
+
* <center><img src="images/scale-flex-height.png"/></center><br>
|
|
41
|
+
* - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio <br>
|
|
42
|
+
* <center><img src="images/scale-stretch.png"/></center>
|
|
43
|
+
* @property {string|HTMLElement} [scaleTarget] - the HTML Element to be used as the reference target when using automatic scaling (by default melonJS will use the parent container of the div element containing the canvas)
|
|
44
|
+
* @property {boolean} [preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
45
|
+
* @property {"sorting"|"z-buffer"} [depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL
|
|
46
|
+
* @property {("default"|"high-performance"|"low-power")} [powerPreference="default"] - a hint to the user agent indicating what configuration of GPU is suitable for the WebGL context. To be noted that Safari and Chrome (since version 80) both default to "low-power" to save battery life and improve the user experience on these dual-GPU machines.
|
|
47
|
+
* @property {boolean} [transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
48
|
+
* @property {boolean} [antiAlias=false] - whether to enable or not video scaling interpolation
|
|
49
|
+
* @property {boolean} [consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
50
|
+
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
51
|
+
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
52
|
+
* @param {Compositor} [options.compositor] - a custom compositor class (WebGL only)
|
|
53
|
+
* @see Application
|
|
54
|
+
* @memberof Application
|
|
55
|
+
*/
|
package/src/audio/audio.js
CHANGED
|
@@ -76,15 +76,13 @@ export let stopOnAudioError = true;
|
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Initialize and configure the audio support.<br>
|
|
79
|
-
* melonJS supports a wide array of audio codecs that have varying browser support :
|
|
80
|
-
* <i> ("mp3", "mpeg", opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac")</i>.<br>
|
|
81
79
|
* For a maximum browser coverage the recommendation is to use at least two of them,
|
|
82
80
|
* typically default to webm and then fallback to mp3 for the best balance of small filesize and high quality,
|
|
83
81
|
* webm has nearly full browser coverage with a great combination of compression and quality, and mp3 will fallback gracefully for other browsers.
|
|
84
82
|
* It is important to remember that melonJS selects the first compatible sound based on the list of extensions and given order passed here.
|
|
85
83
|
* So if you want webm to be used before mp3, you need to put the audio format in that order.
|
|
86
84
|
* @function audio.init
|
|
87
|
-
* @param {
|
|
85
|
+
* @param {"mp3"|"mpeg"|"opus"|"ogg"|"oga"|"wav"|"aac"|"caf"|"m4a"|"m4b"|"mp4"|"weba"|"webm"|"dolby"|"flac"} [format="mp3"] - audio format to prioritize
|
|
88
86
|
* @returns {boolean} Indicates whether audio initialization was successful
|
|
89
87
|
* @example
|
|
90
88
|
* // initialize the "sound engine", giving "webm" as default desired audio format, and "mp3" as a fallback
|
|
@@ -93,7 +91,7 @@ export let stopOnAudioError = true;
|
|
|
93
91
|
* return;
|
|
94
92
|
* }
|
|
95
93
|
*/
|
|
96
|
-
|
|
94
|
+
export function init(format = "mp3") {
|
|
97
95
|
// convert it into an array
|
|
98
96
|
audioExts = format.split(",");
|
|
99
97
|
|
|
@@ -103,7 +101,7 @@ export let stopOnAudioError = true;
|
|
|
103
101
|
/**
|
|
104
102
|
* check if the given audio format is supported
|
|
105
103
|
* @function audio.hasFormat
|
|
106
|
-
* @param {
|
|
104
|
+
* @param {"mp3"|"mpeg"|"opus"|"ogg"|"oga"|"wav"|"aac"|"caf"|"m4a"|"m4b"|"mp4"|"weba"|"webm"|"dolby"|"flac"} codec - the audio format to check for support
|
|
107
105
|
* @returns {boolean} return true if the given audio format is supported
|
|
108
106
|
*/
|
|
109
107
|
export function hasFormat(codec) {
|