melonjs 14.2.0 → 14.3.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/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 +1 -1
- 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 +153 -9
- package/dist/melonjs.mjs/application/header.js +34 -0
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +28 -0
- package/dist/melonjs.mjs/audio/audio.js +1 -1
- package/dist/melonjs.mjs/camera/camera2d.js +2 -2
- package/dist/melonjs.mjs/entity/entity.js +1 -1
- package/dist/melonjs.mjs/game.js +1 -1
- package/dist/melonjs.mjs/geometries/ellipse.js +1 -1
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +1 -1
- package/dist/melonjs.mjs/geometries/point.js +1 -1
- package/dist/melonjs.mjs/geometries/poly.js +1 -1
- package/dist/melonjs.mjs/geometries/rectangle.js +1 -1
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +41 -30
- 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 +1 -1
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +2 -2
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- package/dist/melonjs.mjs/level/level.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +2 -2
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/dist/melonjs.mjs/loader/loader.js +1 -1
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/math/color.js +1 -1
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +1 -1
- package/dist/melonjs.mjs/math/matrix3.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
- package/dist/melonjs.mjs/math/vector2.js +1 -1
- package/dist/melonjs.mjs/math/vector3.js +1 -1
- 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 +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 +1 -1
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +1 -1
- package/dist/melonjs.mjs/physics/bounds.js +1 -1
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +174 -146
- package/dist/melonjs.mjs/physics/quadtree.js +1 -1
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +1 -1
- package/dist/melonjs.mjs/physics/world.js +10 -30
- package/dist/melonjs.mjs/plugin/plugin.js +3 -3
- package/dist/melonjs.mjs/renderable/collectable.js +1 -1
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +3 -87
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +2 -2
- package/dist/melonjs.mjs/renderable/light2d.js +1 -1
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +1 -1
- package/dist/melonjs.mjs/renderable/renderable.js +1 -1
- package/dist/melonjs.mjs/renderable/sprite.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +2 -2
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +1 -1
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +1 -1
- package/dist/melonjs.mjs/state/stage.js +2 -2
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -22
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +4 -1
- package/dist/melonjs.mjs/video/renderer.js +8 -1
- package/dist/melonjs.mjs/video/texture/atlas.js +1 -1
- package/dist/melonjs.mjs/video/texture/cache.js +1 -1
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +3 -2
- package/dist/melonjs.mjs/video/utils/autodetect.js +27 -0
- package/dist/melonjs.mjs/video/utils/resize.js +1 -1
- package/dist/melonjs.mjs/video/video.js +15 -147
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +2 -3
- 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 +20 -2
- 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_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +4 -1
- package/dist/melonjs.module.js +20922 -20921
- package/dist/types/application/application.d.ts +144 -0
- package/dist/types/application/header.d.ts +5 -0
- package/dist/types/application/resize.d.ts +5 -0
- package/dist/types/application/settings.d.ts +18 -0
- package/dist/types/audio/audio.d.ts +267 -0
- package/dist/types/camera/camera2d.d.ts +289 -0
- package/dist/types/entity/entity.d.ts +98 -0
- package/{src/game.js → dist/types/game.d.ts} +3 -14
- package/dist/types/geometries/ellipse.d.ts +154 -0
- package/dist/types/geometries/line.d.ts +11 -0
- package/dist/types/geometries/path2d.d.ts +121 -0
- package/dist/types/geometries/point.d.ts +53 -0
- package/dist/types/geometries/poly.d.ts +222 -0
- package/dist/types/geometries/rectangle.d.ts +176 -0
- package/dist/types/geometries/roundrect.d.ts +52 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/input/gamepad.d.ts +95 -0
- package/dist/types/input/input.d.ts +15 -0
- package/dist/types/input/keyboard.d.ts +205 -0
- package/dist/types/input/pointer.d.ts +270 -0
- package/dist/types/input/pointerevent.d.ts +181 -0
- package/dist/types/lang/deprecated.d.ts +53 -0
- package/dist/types/level/level.d.ts +134 -0
- package/dist/types/level/tiled/TMXGroup.d.ts +82 -0
- package/dist/types/level/tiled/TMXLayer.d.ts +180 -0
- package/dist/types/level/tiled/TMXObject.d.ts +195 -0
- package/dist/types/level/tiled/TMXTile.d.ts +78 -0
- package/dist/types/level/tiled/TMXTileMap.d.ts +180 -0
- package/dist/types/level/tiled/TMXTileset.d.ts +94 -0
- package/dist/types/level/tiled/TMXTilesetGroup.d.ts +32 -0
- package/dist/types/level/tiled/TMXUtils.d.ts +47 -0
- package/dist/types/level/tiled/renderer/TMXHexagonalRenderer.d.ts +87 -0
- package/dist/types/level/tiled/renderer/TMXIsometricRenderer.d.ts +55 -0
- package/dist/types/level/tiled/renderer/TMXOrthogonalRenderer.d.ts +43 -0
- package/dist/types/level/tiled/renderer/TMXRenderer.d.ts +75 -0
- package/dist/types/level/tiled/renderer/TMXStaggeredRenderer.d.ts +8 -0
- package/dist/types/loader/loader.d.ts +181 -0
- package/dist/types/loader/loadingscreen.d.ts +18 -0
- package/dist/types/math/color.d.ts +170 -0
- package/dist/types/math/math.d.ts +165 -0
- package/dist/types/math/matrix2.d.ts +209 -0
- package/dist/types/math/matrix3.d.ts +236 -0
- package/dist/types/math/observable_vector2.d.ts +278 -0
- package/dist/types/math/observable_vector3.d.ts +277 -0
- package/dist/types/math/vector2.d.ts +327 -0
- package/dist/types/math/vector3.d.ts +332 -0
- package/dist/types/particles/emitter.d.ts +188 -0
- package/dist/types/particles/particle.d.ts +32 -0
- package/dist/types/particles/settings.d.ts +32 -0
- package/dist/types/physics/body.d.ts +330 -0
- package/dist/types/physics/bounds.d.ts +250 -0
- package/dist/types/physics/collision.d.ts +44 -0
- package/dist/types/physics/detector.d.ts +64 -0
- package/dist/types/physics/quadtree.d.ts +79 -0
- package/dist/types/physics/response.d.ts +37 -0
- package/dist/types/physics/sat.d.ts +48 -0
- package/dist/types/physics/world.d.ts +83 -0
- package/dist/types/plugin/plugin.d.ts +10 -0
- package/dist/types/polyfill/console.d.ts +0 -0
- package/dist/types/polyfill/index.d.ts +1 -0
- package/dist/types/polyfill/performance.d.ts +0 -0
- package/dist/types/polyfill/requestAnimationFrame.d.ts +1 -0
- package/dist/types/polyfill/roundrect.d.ts +0 -0
- package/dist/types/renderable/collectable.d.ts +19 -0
- package/dist/types/renderable/colorlayer.d.ts +28 -0
- package/dist/types/renderable/container.d.ts +302 -0
- package/dist/types/renderable/dragndrop.d.ts +118 -0
- package/dist/types/renderable/imagelayer.d.ts +106 -0
- package/dist/types/renderable/light2d.d.ts +58 -0
- package/dist/types/renderable/nineslicesprite.d.ts +59 -0
- package/dist/types/renderable/renderable.d.ts +402 -0
- package/dist/types/renderable/sprite.d.ts +268 -0
- package/dist/types/renderable/trigger.d.ts +61 -0
- package/dist/types/renderable/ui/uibaseelement.d.ts +95 -0
- package/dist/types/renderable/ui/uispriteelement.d.ts +127 -0
- package/dist/types/renderable/ui/uitextbutton.d.ts +54 -0
- package/dist/types/state/stage.d.ts +116 -0
- package/dist/types/state/state.d.ts +170 -0
- package/dist/types/system/device.d.ts +579 -0
- package/dist/types/system/dom.d.ts +1 -0
- package/dist/types/system/event.d.ts +473 -0
- package/dist/types/system/platform.d.ts +31 -0
- package/dist/types/system/pooling.d.ts +101 -0
- package/dist/types/system/save.d.ts +25 -0
- package/dist/types/system/timer.d.ts +126 -0
- package/dist/types/text/bitmaptext.d.ts +151 -0
- package/dist/types/text/bitmaptextdata.d.ts +35 -0
- package/dist/types/text/glyph.d.ts +28 -0
- package/dist/types/text/text.d.ts +173 -0
- package/dist/types/text/textmetrics.d.ts +47 -0
- package/dist/types/text/textstyle.d.ts +5 -0
- package/dist/types/tweens/easing.d.ts +46 -0
- package/dist/types/tweens/interpolation.d.ts +18 -0
- package/dist/types/tweens/tween.d.ts +195 -0
- package/dist/types/utils/agent.d.ts +21 -0
- package/dist/types/utils/array.d.ts +39 -0
- package/dist/types/utils/file.d.ts +18 -0
- package/dist/types/utils/function.d.ts +32 -0
- package/dist/types/utils/string.d.ts +50 -0
- package/dist/types/utils/utils.d.ts +17 -0
- package/dist/types/video/canvas/canvas_renderer.d.ts +380 -0
- package/dist/types/video/renderer.d.ts +222 -0
- package/dist/types/video/texture/atlas.d.ts +201 -0
- package/dist/types/video/texture/cache.d.ts +45 -0
- package/dist/types/video/texture/canvas_texture.d.ts +78 -0
- package/dist/types/video/utils/autodetect.d.ts +7 -0
- package/dist/types/video/utils/resize.d.ts +4 -0
- package/dist/types/video/video.d.ts +92 -0
- package/dist/types/video/webgl/buffer/vertex.d.ts +56 -0
- package/dist/types/video/webgl/glshader.d.ts +93 -0
- package/dist/types/video/webgl/utils/attributes.d.ts +4 -0
- package/dist/types/video/webgl/utils/precision.d.ts +13 -0
- package/dist/types/video/webgl/utils/program.d.ts +5 -0
- package/dist/types/video/webgl/utils/string.d.ts +5 -0
- package/dist/types/video/webgl/utils/uniforms.d.ts +4 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +174 -0
- package/dist/types/video/webgl/webgl_renderer.d.ts +429 -0
- package/package.json +4 -4
- package/src/application/application.js +151 -7
- package/src/application/header.js +25 -0
- package/src/{video/utils → application}/resize.js +9 -6
- package/src/application/settings.js +19 -0
- package/src/camera/camera2d.js +1 -1
- package/src/index.js +34 -23
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +1 -1
- package/src/level/level.js +1 -1
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXTileMap.js +2 -2
- package/src/loader/loadingscreen.js +1 -1
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +172 -145
- package/src/physics/world.js +10 -30
- package/src/renderable/container.js +7 -91
- package/src/renderable/imagelayer.js +1 -1
- package/src/renderable/trigger.js +1 -1
- package/src/renderable/ui/uibaseelement.js +1 -1
- package/src/state/stage.js +1 -1
- package/src/state/state.js +1 -1
- package/src/system/device.js +0 -20
- package/src/tweens/tween.js +1 -1
- package/src/video/canvas/canvas_renderer.js +3 -0
- package/src/video/renderer.js +7 -0
- package/src/video/texture/canvas_texture.js +2 -1
- package/src/video/utils/autodetect.js +18 -0
- package/src/video/video.js +13 -145
- package/src/video/webgl/glshader.js +3 -4
- package/src/video/webgl/utils/precision.js +18 -0
- package/src/video/webgl/webgl_renderer.js +3 -0
|
@@ -1,8 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { autoDetectRenderer } from "../video/utils/autodetect.js";
|
|
2
|
+
import CanvasRenderer from "./../video/canvas/canvas_renderer.js";
|
|
3
|
+
import * as device from "./../system/device.js";
|
|
2
4
|
import * as event from "./../system/event.js";
|
|
5
|
+
import utils from "./../utils/utils.js";
|
|
3
6
|
import timer from "./../system/timer.js";
|
|
4
7
|
import state from "./../state/state.js";
|
|
5
8
|
import World from "./../physics/world.js";
|
|
9
|
+
import { onresize } from "./resize.js";
|
|
10
|
+
import { defaultSettings } from "./settings.js";
|
|
11
|
+
import { consoleHeader } from "./header.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Select the HTML5 Canvas renderer
|
|
15
|
+
* @constant
|
|
16
|
+
*/
|
|
17
|
+
const CANVAS = 0;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Select the WebGL renderer
|
|
21
|
+
* @constant
|
|
22
|
+
*/
|
|
23
|
+
const WEBGL = 1;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
|
|
27
|
+
* @constant
|
|
28
|
+
*/
|
|
29
|
+
const AUTO = 2;
|
|
6
30
|
|
|
7
31
|
/**
|
|
8
32
|
* @classdesc
|
|
@@ -11,7 +35,22 @@ import World from "./../physics/world.js";
|
|
|
11
35
|
* @see game
|
|
12
36
|
*/
|
|
13
37
|
export default class Application {
|
|
14
|
-
|
|
38
|
+
/**
|
|
39
|
+
* @param {number} width - The width of the canvas viewport
|
|
40
|
+
* @param {number} height - The height of the canvas viewport
|
|
41
|
+
* @param {object} [options] - The optional video/renderer parameters.<br> (see Renderer(s) documentation for further specific options)
|
|
42
|
+
* @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
|
|
43
|
+
* @param {number|Renderer} [options.renderer=video.AUTO] - renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO), or a custom renderer class
|
|
44
|
+
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
45
|
+
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
46
|
+
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
47
|
+
* @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.
|
|
48
|
+
* @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
49
|
+
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
|
|
50
|
+
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
51
|
+
* @throws Will throw an exception if it fails to instantiate a renderer
|
|
52
|
+
*/
|
|
53
|
+
constructor(width, height, options) {
|
|
15
54
|
|
|
16
55
|
/**
|
|
17
56
|
* the parent HTML element holding the main canvas of this application
|
|
@@ -19,6 +58,12 @@ import World from "./../physics/world.js";
|
|
|
19
58
|
*/
|
|
20
59
|
this.parentElement = undefined;
|
|
21
60
|
|
|
61
|
+
/**
|
|
62
|
+
* a reference to the active Canvas or WebGL active renderer renderer
|
|
63
|
+
* @type {CanvasRenderer|WebGLRenderer}
|
|
64
|
+
*/
|
|
65
|
+
this.renderer = undefined;
|
|
66
|
+
|
|
22
67
|
/**
|
|
23
68
|
* the active stage "default" camera
|
|
24
69
|
* @type {Camera2d}
|
|
@@ -64,6 +109,12 @@ import World from "./../physics/world.js";
|
|
|
64
109
|
*/
|
|
65
110
|
this.isInitialized = false;
|
|
66
111
|
|
|
112
|
+
/**
|
|
113
|
+
* the given settings used when creating this application
|
|
114
|
+
* @type {Object}
|
|
115
|
+
*/
|
|
116
|
+
this.settings = undefined;
|
|
117
|
+
|
|
67
118
|
// to know when we have to refresh the display
|
|
68
119
|
this.isDirty = true;
|
|
69
120
|
|
|
@@ -85,18 +136,111 @@ import World from "./../physics/world.js";
|
|
|
85
136
|
this.updateDelta = 0;
|
|
86
137
|
this.lastUpdateStart = null;
|
|
87
138
|
this.updateAverageDelta = 0;
|
|
139
|
+
|
|
140
|
+
// when using the default game application, legacy is set to true
|
|
141
|
+
// and init is called through the legacy video.init() call
|
|
142
|
+
if (options.legacy !== true) {
|
|
143
|
+
this.init(width, height, options);
|
|
144
|
+
}
|
|
88
145
|
}
|
|
89
146
|
|
|
90
147
|
/**
|
|
91
148
|
* init the game instance (create a physic world, update starting time, etc..)
|
|
92
149
|
*/
|
|
93
|
-
init() {
|
|
150
|
+
init(width, height, options) {
|
|
151
|
+
|
|
152
|
+
this.settings = Object.assign(defaultSettings, options || {});
|
|
153
|
+
|
|
154
|
+
// sanitize potential given parameters
|
|
155
|
+
this.settings.width = width;
|
|
156
|
+
this.settings.height = height;
|
|
157
|
+
this.settings.transparent = !!(this.settings.transparent);
|
|
158
|
+
this.settings.antiAlias = !!(this.settings.antiAlias);
|
|
159
|
+
this.settings.failIfMajorPerformanceCaveat = !!(this.settings.failIfMajorPerformanceCaveat);
|
|
160
|
+
this.settings.subPixel = !!(this.settings.subPixel);
|
|
161
|
+
this.settings.verbose = !!(this.settings.verbose);
|
|
162
|
+
if (this.settings.scaleMethod.search(/^(fill-(min|max)|fit|flex(-(width|height))?|stretch)$/) !== -1) {
|
|
163
|
+
this.settings.autoScale = (this.settings.scale === "auto") || true;
|
|
164
|
+
} else {
|
|
165
|
+
// default scaling method
|
|
166
|
+
this.settings.scaleMethod = "fit";
|
|
167
|
+
this.settings.autoScale = (this.settings.scale === "auto") || false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// override renderer settings if &webgl or &canvas is defined in the URL
|
|
171
|
+
var uriFragment = utils.getUriFragment();
|
|
172
|
+
if (uriFragment.webgl === true || uriFragment.webgl1 === true || uriFragment.webgl2 === true) {
|
|
173
|
+
this.settings.renderer = WEBGL;
|
|
174
|
+
if (uriFragment.webgl1 === true) {
|
|
175
|
+
this.settings.preferWebGL1 = true;
|
|
176
|
+
}
|
|
177
|
+
} else if (uriFragment.canvas === true) {
|
|
178
|
+
this.settings.renderer = CANVAS;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// normalize scale
|
|
182
|
+
this.settings.scale = (this.settings.autoScale) ? 1.0 : (+this.settings.scale || 1.0);
|
|
183
|
+
|
|
184
|
+
// default scaled size value
|
|
185
|
+
this.settings.zoomX = width * this.settings.scale;
|
|
186
|
+
this.settings.zoomY = height * this.settings.scale;
|
|
187
|
+
|
|
188
|
+
if (typeof this.settings.renderer === "number") {
|
|
189
|
+
switch (this.settings.renderer) {
|
|
190
|
+
case AUTO:
|
|
191
|
+
case WEBGL:
|
|
192
|
+
this.renderer = autoDetectRenderer(this.settings);
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
this.renderer = new CanvasRenderer(this.settings);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
} else {
|
|
199
|
+
var CustomRenderer = this.settings.renderer;
|
|
200
|
+
// a renderer class
|
|
201
|
+
this.renderer = new CustomRenderer(this.settings);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// register to the channel
|
|
205
|
+
event.on(event.WINDOW_ONRESIZE, () => { onresize(this); }, this);
|
|
206
|
+
event.on(event.WINDOW_ONORIENTATION_CHANGE, () => { onresize(this); }, this);
|
|
207
|
+
|
|
208
|
+
// add our canvas (default to document.body if settings.parent is undefined)
|
|
209
|
+
this.parentElement = device.getElement(this.settings.parent);
|
|
210
|
+
this.parentElement.appendChild(this.renderer.getCanvas());
|
|
211
|
+
|
|
212
|
+
// Mobile browser hacks
|
|
213
|
+
if (device.platform.isMobile) {
|
|
214
|
+
// Prevent the webview from moving on a swipe
|
|
215
|
+
device.enableSwipe(false);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// trigger an initial resize();
|
|
219
|
+
onresize(this);
|
|
220
|
+
|
|
221
|
+
// add an observer to detect when the dom tree is modified
|
|
222
|
+
if ("MutationObserver" in globalThis) {
|
|
223
|
+
// Create an observer instance linked to the callback function
|
|
224
|
+
var observer = new MutationObserver(onresize.bind(this, this));
|
|
225
|
+
|
|
226
|
+
// Start observing the target node for configured mutations
|
|
227
|
+
observer.observe(this.parentElement, {
|
|
228
|
+
attributes: false, childList: true, subtree: true
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (this.settings.consoleHeader !== false) {
|
|
233
|
+
consoleHeader(this);
|
|
234
|
+
}
|
|
235
|
+
|
|
94
236
|
// create a new physic world
|
|
95
237
|
this.world = new World();
|
|
96
238
|
// set the reference to this application instance
|
|
97
239
|
this.world.app = this;
|
|
98
240
|
this.lastUpdate = globalThis.performance.now();
|
|
241
|
+
|
|
99
242
|
this.isInitialized = true;
|
|
243
|
+
|
|
100
244
|
event.emit(event.GAME_INIT, this);
|
|
101
245
|
}
|
|
102
246
|
|
|
@@ -213,21 +357,21 @@ import World from "./../physics/world.js";
|
|
|
213
357
|
* @param {Stage} stage - the current stage
|
|
214
358
|
*/
|
|
215
359
|
draw(stage) {
|
|
216
|
-
if (renderer.isContextValid === true && (this.isDirty || this.isAlwaysDirty)) {
|
|
360
|
+
if (this.renderer.isContextValid === true && (this.isDirty || this.isAlwaysDirty)) {
|
|
217
361
|
// publish notification
|
|
218
362
|
event.emit(event.GAME_BEFORE_DRAW, globalThis.performance.now());
|
|
219
363
|
|
|
220
364
|
// prepare renderer to draw a new frame
|
|
221
|
-
renderer.clear();
|
|
365
|
+
this.renderer.clear();
|
|
222
366
|
|
|
223
367
|
// render the stage
|
|
224
|
-
stage.draw(renderer);
|
|
368
|
+
stage.draw(this.renderer);
|
|
225
369
|
|
|
226
370
|
// set back to flag
|
|
227
371
|
this.isDirty = false;
|
|
228
372
|
|
|
229
373
|
// flush/render our frame
|
|
230
|
-
renderer.flush();
|
|
374
|
+
this.renderer.flush();
|
|
231
375
|
|
|
232
376
|
// publish notification
|
|
233
377
|
event.emit(event.GAME_AFTER_DRAW, globalThis.performance.now());
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as device from "../system/device";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* display information
|
|
5
|
+
* @param {Application} game - the game application instance calling this function
|
|
6
|
+
*/
|
|
7
|
+
export function consoleHeader(app) {
|
|
8
|
+
var renderType = app.renderer.type;
|
|
9
|
+
var gpu_renderer = (typeof app.renderer.GPURenderer === "string") ? " (" + app.renderer.GPURenderer + ")" : "";
|
|
10
|
+
var audioType = device.hasWebAudio ? "Web Audio" : "HTML5 Audio";
|
|
11
|
+
|
|
12
|
+
// output video information in the console
|
|
13
|
+
console.log(
|
|
14
|
+
renderType + " renderer" + gpu_renderer + " | " +
|
|
15
|
+
audioType + " | " +
|
|
16
|
+
"pixel ratio " + device.devicePixelRatio + " | " +
|
|
17
|
+
(device.platform.nodeJS ? "node.js" : device.platform.isMobile ? "mobile" : "desktop") + " | " +
|
|
18
|
+
device.getScreenOrientation() + " | " +
|
|
19
|
+
device.language
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
console.log( "resolution: " + "requested " + app.settings.width + "x" + app.settings.height +
|
|
23
|
+
", got " + app.renderer.getWidth() + "x" + app.renderer.getHeight()
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import * as device from "
|
|
2
|
-
import game from "./../../game.js";
|
|
1
|
+
import * as device from "./../system/device";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* scale the "displayed" canvas by the given scalar.
|
|
6
5
|
* this will modify the size of canvas element directly.
|
|
7
6
|
* Only use this if you are not using the automatic scaling feature.
|
|
7
|
+
* @param {Application} game - the game application instance triggering the resize
|
|
8
8
|
* @param {number} x - x scaling multiplier
|
|
9
9
|
* @param {number} y - y scaling multiplier
|
|
10
10
|
*/
|
|
11
|
-
function scale(
|
|
11
|
+
function scale(game, x, y) {
|
|
12
|
+
var renderer = game.renderer;
|
|
12
13
|
var canvas = renderer.getCanvas();
|
|
13
14
|
var context = renderer.getContext();
|
|
14
15
|
var settings = renderer.settings;
|
|
@@ -34,8 +35,10 @@ function scale(renderer, x, y) {
|
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* callback for window resize event
|
|
38
|
+
* @param {Application} game - the game application instance triggering the resize
|
|
37
39
|
*/
|
|
38
|
-
export function onresize(
|
|
40
|
+
export function onresize(game) {
|
|
41
|
+
var renderer = game.renderer;
|
|
39
42
|
var settings = renderer.settings;
|
|
40
43
|
var scaleX = 1, scaleY = 1;
|
|
41
44
|
|
|
@@ -99,9 +102,9 @@ export function onresize(renderer) {
|
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
// adjust scaling ratio based on the new scaling ratio
|
|
102
|
-
scale(
|
|
105
|
+
scale(game, scaleX, scaleY);
|
|
103
106
|
} else {
|
|
104
107
|
// adjust scaling ratio based on the given settings
|
|
105
|
-
scale(
|
|
108
|
+
scale(game, settings.scale, settings.scale);
|
|
106
109
|
}
|
|
107
110
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// default settings
|
|
2
|
+
export const defaultSettings = {
|
|
3
|
+
parent : undefined,
|
|
4
|
+
renderer : 2, // AUTO
|
|
5
|
+
autoScale : false,
|
|
6
|
+
scale : 1.0,
|
|
7
|
+
scaleMethod : "manual",
|
|
8
|
+
transparent : false,
|
|
9
|
+
premultipliedAlpha: true,
|
|
10
|
+
blendMode : "normal",
|
|
11
|
+
antiAlias : false,
|
|
12
|
+
failIfMajorPerformanceCaveat : true,
|
|
13
|
+
subPixel : false,
|
|
14
|
+
preferWebGL1 : false,
|
|
15
|
+
powerPreference : "default",
|
|
16
|
+
verbose : false,
|
|
17
|
+
consoleHeader : true,
|
|
18
|
+
legacy : false
|
|
19
|
+
};
|
package/src/camera/camera2d.js
CHANGED
|
@@ -10,7 +10,7 @@ import * as event from "./../system/event.js";
|
|
|
10
10
|
import pool from "./../system/pooling.js";
|
|
11
11
|
import Renderable from "./../renderable/renderable.js";
|
|
12
12
|
import {clamp, toBeCloseTo} from "./../math/math.js";
|
|
13
|
-
import game from "
|
|
13
|
+
import { game } from "../index.js";
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// some ref shortcut
|
package/src/index.js
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
// ES5/ES6 polyfills
|
|
2
2
|
import "./polyfill/index.js";
|
|
3
3
|
|
|
4
|
-
// utility classes
|
|
5
|
-
import * as audio from "./audio/audio.js";
|
|
6
|
-
import collision from "./physics/collision.js";
|
|
7
|
-
import * as event from "./system/event.js";
|
|
8
|
-
import * as device from "./system/device.js";
|
|
9
|
-
import game from "./game.js";
|
|
10
|
-
import loader from "./loader/loader.js";
|
|
11
|
-
import * as Math from "./math/math.js";
|
|
12
|
-
import utils from "./utils/utils.js";
|
|
13
|
-
import * as input from "./input/input.js";
|
|
14
|
-
import { plugin, plugins } from "./plugin/plugin.js";
|
|
15
|
-
import * as video from "./video/video.js";
|
|
16
|
-
import save from "./system/save.js";
|
|
17
|
-
import timer from "./system/timer.js";
|
|
18
|
-
import pool from "./system/pooling.js";
|
|
19
|
-
import state from "./state/state.js";
|
|
20
|
-
import level from "./level/level.js";
|
|
21
|
-
|
|
22
4
|
// class definition
|
|
23
5
|
import Color from "./math/color.js";
|
|
24
6
|
import Vector2d from "./math/vector2.js";
|
|
@@ -45,9 +27,6 @@ import CanvasRenderer from "./video/canvas/canvas_renderer.js";
|
|
|
45
27
|
import CanvasTexture from "./video/texture/canvas_texture.js";
|
|
46
28
|
import { TextureAtlas } from "./video/texture/atlas.js";
|
|
47
29
|
import Renderable from "./renderable/renderable.js";
|
|
48
|
-
import Text from "./text/text.js";
|
|
49
|
-
import BitmapText from "./text/bitmaptext.js";
|
|
50
|
-
import BitmapTextData from "./text/bitmaptextdata.js";
|
|
51
30
|
import ColorLayer from "./renderable/colorlayer.js";
|
|
52
31
|
import ImageLayer from "./renderable/imagelayer.js";
|
|
53
32
|
import Sprite from "./renderable/sprite.js";
|
|
@@ -58,6 +37,9 @@ import UISpriteElement from "./renderable/ui/uispriteelement.js";
|
|
|
58
37
|
import Collectable from "./renderable/collectable.js";
|
|
59
38
|
import Trigger from "./renderable/trigger.js";
|
|
60
39
|
import Light2d from "./renderable/light2d.js";
|
|
40
|
+
import Text from "./text/text.js";
|
|
41
|
+
import BitmapText from "./text/bitmaptext.js";
|
|
42
|
+
import BitmapTextData from "./text/bitmaptextdata.js";
|
|
61
43
|
import { Draggable, DropTarget } from "./renderable/dragndrop.js";
|
|
62
44
|
import TMXRenderer from "./level/tiled/renderer/TMXRenderer.js";
|
|
63
45
|
import TMXOrthogonalRenderer from "./level/tiled/renderer/TMXOrthogonalRenderer.js";
|
|
@@ -78,6 +60,24 @@ import ParticleEmitterSettings from "./particles/settings.js";
|
|
|
78
60
|
import ParticleEmitter from "./particles/emitter.js";
|
|
79
61
|
import Particle from "./particles/particle.js";
|
|
80
62
|
import Entity from "./entity/entity.js";
|
|
63
|
+
import Application from "./application/application.js";
|
|
64
|
+
|
|
65
|
+
// utility classes
|
|
66
|
+
import * as audio from "./audio/audio.js";
|
|
67
|
+
import collision from "./physics/collision.js";
|
|
68
|
+
import * as event from "./system/event.js";
|
|
69
|
+
import * as device from "./system/device.js";
|
|
70
|
+
import loader from "./loader/loader.js";
|
|
71
|
+
import * as Math from "./math/math.js";
|
|
72
|
+
import utils from "./utils/utils.js";
|
|
73
|
+
import * as input from "./input/input.js";
|
|
74
|
+
import { plugin, plugins } from "./plugin/plugin.js";
|
|
75
|
+
import * as video from "./video/video.js";
|
|
76
|
+
import save from "./system/save.js";
|
|
77
|
+
import timer from "./system/timer.js";
|
|
78
|
+
import pool from "./system/pooling.js";
|
|
79
|
+
import state from "./state/state.js";
|
|
80
|
+
import level from "./level/level.js";
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
/**
|
|
@@ -95,7 +95,6 @@ export {
|
|
|
95
95
|
collision,
|
|
96
96
|
device,
|
|
97
97
|
event,
|
|
98
|
-
game,
|
|
99
98
|
loader,
|
|
100
99
|
level,
|
|
101
100
|
input,
|
|
@@ -169,7 +168,8 @@ export {
|
|
|
169
168
|
ParticleEmitter,
|
|
170
169
|
ParticleEmitterSettings,
|
|
171
170
|
Particle,
|
|
172
|
-
Entity
|
|
171
|
+
Entity,
|
|
172
|
+
Application
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
// Backward compatibility for deprecated method or properties
|
|
@@ -192,6 +192,14 @@ export var initialized = false;
|
|
|
192
192
|
*/
|
|
193
193
|
export var skipAutoInit = false;
|
|
194
194
|
|
|
195
|
+
/*
|
|
196
|
+
* game is a default instance of a melonJS Application and represents your current game,
|
|
197
|
+
* it contains all the objects, tilemap layers, current viewport, collision map, etc...<br>
|
|
198
|
+
* @namespace game
|
|
199
|
+
* @see Application
|
|
200
|
+
*/
|
|
201
|
+
export const game = new Application(0, 0, {legacy:true});
|
|
202
|
+
|
|
195
203
|
/**
|
|
196
204
|
* initialize the melonJS library.
|
|
197
205
|
* this is automatically called unless me.skipAutoInit is set to true,
|
|
@@ -206,6 +214,9 @@ export function boot() {
|
|
|
206
214
|
return;
|
|
207
215
|
}
|
|
208
216
|
|
|
217
|
+
// output melonJS version in the console
|
|
218
|
+
console.log("melonJS 2 (v" + version + ") | http://melonjs.org" );
|
|
219
|
+
|
|
209
220
|
// register all built-ins objects into the object pool
|
|
210
221
|
pool.register("me.Entity", Entity);
|
|
211
222
|
pool.register("me.Collectable", Collectable);
|
package/src/input/pointer.js
CHANGED
|
@@ -9,7 +9,7 @@ import pool from "./../system/pooling.js";
|
|
|
9
9
|
import * as device from "./../system/device.js";
|
|
10
10
|
import Pointer from "./pointer.js";
|
|
11
11
|
import Rect from "./../geometries/rectangle.js";
|
|
12
|
-
import game from "
|
|
12
|
+
import { game } from "../index.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* A pool of `Pointer` objects to cache pointer/touch event coordinates.
|
package/src/level/level.js
CHANGED
|
@@ -2,7 +2,7 @@ import utils from "./../utils/utils.js";
|
|
|
2
2
|
import * as event from "./../system/event.js";
|
|
3
3
|
import state from "./../state/state.js";
|
|
4
4
|
import loader from "./../loader/loader.js";
|
|
5
|
-
import game from "
|
|
5
|
+
import { game } from "../index.js";
|
|
6
6
|
import TMXTileMap from "./tiled/TMXTileMap.js";
|
|
7
7
|
|
|
8
8
|
|
|
@@ -4,7 +4,7 @@ import * as TMXUtils from "./TMXUtils.js";
|
|
|
4
4
|
import Tile from "./TMXTile.js";
|
|
5
5
|
import Renderable from "./../../renderable/renderable.js";
|
|
6
6
|
import CanvasRenderer from "./../../video/canvas/canvas_renderer";
|
|
7
|
-
import game from "
|
|
7
|
+
import { game } from "../../index.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Create required arrays for the given layer object
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import pool from "./../../system/pooling.js";
|
|
2
2
|
import * as event from "./../../system/event.js";
|
|
3
|
-
import game from "
|
|
3
|
+
import { game } from "../../index.js";
|
|
4
4
|
import collision from "./../../physics/collision.js";
|
|
5
5
|
import Body from "./../../physics/body.js";
|
|
6
6
|
import TMXOrthogonalRenderer from "./renderer/TMXOrthogonalRenderer.js";
|
|
@@ -12,7 +12,7 @@ import TMXTilesetGroup from "./TMXTilesetGroup.js";
|
|
|
12
12
|
import TMXGroup from "./TMXGroup.js";
|
|
13
13
|
import TMXLayer from "./TMXLayer.js";
|
|
14
14
|
import { applyTMXProperties } from "./TMXUtils.js";
|
|
15
|
-
import Container from "
|
|
15
|
+
import Container from "../../renderable/container.js";
|
|
16
16
|
|
|
17
17
|
// constant to identify the collision object layer
|
|
18
18
|
const COLLISION_GROUP = "collision";
|
package/src/physics/collision.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { game } from "../index.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Collision detection (and projection-based collision response) of 2D shapes.<br>
|
|
@@ -117,7 +117,7 @@ var collision = {
|
|
|
117
117
|
* // ...
|
|
118
118
|
* }
|
|
119
119
|
*/
|
|
120
|
-
rayCast(line, result) { return rayCast(line, result); }
|
|
120
|
+
rayCast(line, result) { return game.world.rayCast(line, result); }
|
|
121
121
|
};
|
|
122
122
|
|
|
123
123
|
export default collision;
|