melonjs 15.2.0 → 15.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/README.md +5 -5
- 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 +24 -20
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +10 -4
- package/dist/melonjs.mjs/application/settings.js +37 -1
- package/dist/melonjs.mjs/audio/audio.js +1 -1
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.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 +4 -2
- 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 +1 -1
- package/dist/melonjs.mjs/input/pointerevent.js +1 -1
- package/dist/melonjs.mjs/lang/console.js +1 -1
- package/dist/melonjs.mjs/lang/deprecated.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +117 -90
- package/dist/melonjs.mjs/level/tiled/constants.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/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 +1 -1
- package/dist/melonjs.mjs/loader/settings.js +1 -1
- package/dist/melonjs.mjs/math/color.js +4 -4
- 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/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 +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 +1 -1
- package/dist/melonjs.mjs/physics/detector.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +6 -14
- package/dist/melonjs.mjs/renderable/sprite.js +1 -1
- package/dist/melonjs.mjs/renderable/trigger.js +1 -1
- 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 +12 -13
- package/dist/melonjs.mjs/state/state.js +4 -14
- package/dist/melonjs.mjs/system/device.js +3 -1
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +24 -2
- 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 +1 -1
- 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 +2 -11
- package/dist/melonjs.mjs/video/renderer.js +2 -15
- 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 +1 -1
- package/dist/melonjs.mjs/video/utils/autodetect.js +1 -1
- package/dist/melonjs.mjs/video/video.js +4 -54
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +1 -1
- 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 +1 -1
- 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 +13 -16
- package/dist/melonjs.module.js +262 -250
- package/dist/types/application/application.d.ts +4 -27
- package/dist/types/application/settings.d.ts +64 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/level/tiled/TMXUtils.d.ts +18 -37
- package/dist/types/renderable/renderable.d.ts +1 -2
- package/dist/types/state/stage.d.ts +3 -2
- package/dist/types/system/device.d.ts +1 -0
- package/dist/types/system/event.d.ts +20 -0
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -23
- package/dist/types/video/renderer.d.ts +3 -30
- package/dist/types/video/video.d.ts +3 -57
- package/dist/types/video/webgl/webgl_renderer.d.ts +1 -34
- package/package.json +7 -7
- package/src/application/application.js +22 -18
- package/src/application/resize.js +8 -2
- package/src/application/settings.js +36 -0
- package/src/index.js +2 -0
- package/src/level/tiled/TMXUtils.js +116 -92
- package/src/math/color.js +3 -3
- package/src/renderable/renderable.js +5 -13
- package/src/state/stage.js +11 -12
- package/src/state/state.js +2 -12
- package/src/system/device.js +2 -0
- package/src/system/event.js +22 -0
- package/src/video/canvas/canvas_renderer.js +1 -10
- package/src/video/renderer.js +1 -14
- package/src/video/video.js +7 -30
- package/src/video/webgl/webgl_renderer.js +12 -15
|
@@ -8,35 +8,14 @@ export default class Application {
|
|
|
8
8
|
/**
|
|
9
9
|
* @param {number} width - The width of the canvas viewport
|
|
10
10
|
* @param {number} height - The height of the canvas viewport
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
|
|
13
|
-
* @param {number|Renderer} [options.renderer=AUTO] - renderer to use (CANVAS, WEBGL, AUTO), or a custom renderer class
|
|
14
|
-
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
15
|
-
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
16
|
-
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
17
|
-
* @param {boolean} [options.depthTest="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
18
|
-
* @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.
|
|
19
|
-
* @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
20
|
-
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
|
|
21
|
-
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
11
|
+
* @param {Application.Settings} [options] - The optional parameters for the application and default renderer
|
|
22
12
|
* @throws Will throw an exception if it fails to instantiate a renderer
|
|
23
13
|
* @example
|
|
24
14
|
* let my game = new Application(640, 480, {renderer: me.video.AUTO}) {
|
|
25
15
|
* ....
|
|
26
16
|
* }
|
|
27
17
|
*/
|
|
28
|
-
constructor(width: number, height: number, options?:
|
|
29
|
-
parent?: string | HTMLElement | undefined;
|
|
30
|
-
renderer?: number | Renderer;
|
|
31
|
-
scale?: string | number | undefined;
|
|
32
|
-
scaleMethod?: string | undefined;
|
|
33
|
-
preferWebGL1?: boolean | undefined;
|
|
34
|
-
depthTest?: boolean | undefined;
|
|
35
|
-
powerPreference?: string | undefined;
|
|
36
|
-
transparent?: boolean | undefined;
|
|
37
|
-
antiAlias?: boolean | undefined;
|
|
38
|
-
consoleHeader?: boolean | undefined;
|
|
39
|
-
} | undefined);
|
|
18
|
+
constructor(width: number, height: number, options?: any);
|
|
40
19
|
/**
|
|
41
20
|
* the parent HTML element holding the main canvas of this application
|
|
42
21
|
* @type {HTMLElement}
|
|
@@ -138,14 +117,12 @@ export default class Application {
|
|
|
138
117
|
/**
|
|
139
118
|
* update all objects related to this game active scene/stage
|
|
140
119
|
* @param {number} time - current timestamp as provided by the RAF callback
|
|
141
|
-
* @param {Stage} stage - the current stage
|
|
142
120
|
*/
|
|
143
|
-
update(time: number
|
|
121
|
+
update(time: number): void;
|
|
144
122
|
/**
|
|
145
123
|
* draw the active scene/stage associated to this game
|
|
146
|
-
* @param {Stage} stage - the current stage
|
|
147
124
|
*/
|
|
148
|
-
draw(
|
|
125
|
+
draw(): void;
|
|
149
126
|
}
|
|
150
127
|
import CanvasRenderer from "./../video/canvas/canvas_renderer.js";
|
|
151
128
|
import World from "./../physics/world.js";
|
|
@@ -4,6 +4,7 @@ export namespace defaultSettings {
|
|
|
4
4
|
const autoScale: boolean;
|
|
5
5
|
const scale: number;
|
|
6
6
|
const scaleMethod: string;
|
|
7
|
+
const scaleTarget: undefined;
|
|
7
8
|
const transparent: boolean;
|
|
8
9
|
const premultipliedAlpha: boolean;
|
|
9
10
|
const blendMode: string;
|
|
@@ -16,3 +17,66 @@ export namespace defaultSettings {
|
|
|
16
17
|
const consoleHeader: boolean;
|
|
17
18
|
const legacy: boolean;
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Application & Renderer Settings definition.
|
|
22
|
+
*/
|
|
23
|
+
export type Settings = {
|
|
24
|
+
/**
|
|
25
|
+
* - the DOM parent element to hold the canvas in the HTML file
|
|
26
|
+
*/
|
|
27
|
+
parent?: string | HTMLElement | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* - renderer to use (CANVAS, WEBGL, AUTO), or a custom renderer class
|
|
30
|
+
*/
|
|
31
|
+
renderer?: number | Renderer;
|
|
32
|
+
/**
|
|
33
|
+
* - enable scaling of the canvas ('auto' for automatic scaling)
|
|
34
|
+
*/
|
|
35
|
+
scale?: string | number | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch') : <br>
|
|
38
|
+
* - <i><b>`fit`</b></i> : Letterboxed; content is scaled to design aspect ratio <br>
|
|
39
|
+
* <center><img src="images/scale-fit.png"/></center><br>
|
|
40
|
+
* - <i><b>`fill-min`</b></i> : Canvas is resized to fit minimum design resolution; content is scaled to design aspect ratio <br>
|
|
41
|
+
* <center><img src="images/scale-fill-min.png"/></center><br>
|
|
42
|
+
* - <i><b>`fill-max`</b></i> : Canvas is resized to fit maximum design resolution; content is scaled to design aspect ratio <br>
|
|
43
|
+
* <center><img src="images/scale-fill-max.png"/></center><br>
|
|
44
|
+
* - <i><b>`flex`</b><</i> : Canvas width & height is resized to fit; content is scaled to design aspect ratio <br>
|
|
45
|
+
* <center><img src="images/scale-flex.png"/></center><br>
|
|
46
|
+
* - <i><b>`flex-width`</b></i> : Canvas width is resized to fit; content is scaled to design aspect ratio <br>
|
|
47
|
+
* <center><img src="images/scale-flex-width.png"/></center><br>
|
|
48
|
+
* - <i><b>`flex-height`</b></i> : Canvas height is resized to fit; content is scaled to design aspect ratio <br>
|
|
49
|
+
* <center><img src="images/scale-flex-height.png"/></center><br>
|
|
50
|
+
* - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio <br>
|
|
51
|
+
* <center><img src="images/scale-stretch.png"/></center>
|
|
52
|
+
*/
|
|
53
|
+
scaleMethod?: string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* - 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)
|
|
56
|
+
*/
|
|
57
|
+
scaleTarget?: string | HTMLElement | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* - if true the renderer will only use WebGL 1
|
|
60
|
+
*/
|
|
61
|
+
preferWebGL1?: boolean | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
64
|
+
*/
|
|
65
|
+
depthTest?: boolean | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* - 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.
|
|
68
|
+
*/
|
|
69
|
+
powerPreference?: string | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* - whether to allow transparent pixels in the front buffer (screen).
|
|
72
|
+
*/
|
|
73
|
+
transparent?: boolean | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* - whether to enable or not video scaling interpolation
|
|
76
|
+
*/
|
|
77
|
+
antiAlias?: boolean | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* - whether to display melonJS version and basic device information in the console
|
|
80
|
+
*/
|
|
81
|
+
consoleHeader?: boolean | undefined;
|
|
82
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -100,6 +100,7 @@ import TMXTileset from "./level/tiled/TMXTileset.js";
|
|
|
100
100
|
import TMXTilesetGroup from "./level/tiled/TMXTilesetGroup.js";
|
|
101
101
|
import TMXTileMap from "./level/tiled/TMXTileMap.js";
|
|
102
102
|
import TMXLayer from "./level/tiled/TMXLayer.js";
|
|
103
|
+
import * as TMXUtils from "./level/tiled/TMXUtils.js";
|
|
103
104
|
import Pointer from "./input/pointer.js";
|
|
104
105
|
import Stage from "./state/stage.js";
|
|
105
106
|
import Camera2d from "./camera/camera2d.js";
|
|
@@ -110,4 +111,4 @@ import ParticleEmitterSettings from "./particles/settings.js";
|
|
|
110
111
|
import Particle from "./particles/particle.js";
|
|
111
112
|
import Entity from "./entity/entity.js";
|
|
112
113
|
import Application from "./application/application.js";
|
|
113
|
-
export { audio, collision, device, event, loader, level, input, Math, plugin, plugins, utils, save, timer, pool, state, video, Color, Vector2d, Vector3d, ObservableVector2d, ObservableVector3d, Matrix2d, Matrix3d, Polygon, Line, Ellipse, Point, Rect, RoundRect, Tween, QuadTree, GLShader, Compositor, PrimitiveCompositor, QuadCompositor, Renderer, WebGLRenderer, CanvasRenderer, CanvasTexture, TextureAtlas, Renderable, Body, Bounds, Text, BitmapText, BitmapTextData, ColorLayer, ImageLayer, Sprite, NineSliceSprite, UIBaseElement, UITextButton, UISpriteElement, Collectable, Trigger, Light2d, Draggable, DropTarget, TMXRenderer, TMXOrthogonalRenderer, TMXIsometricRenderer, TMXHexagonalRenderer, TMXStaggeredRenderer, Tile, TMXTileset, TMXTilesetGroup, TMXTileMap, TMXLayer, Pointer, Stage, Camera2d, Container, World, ParticleEmitter, ParticleEmitterSettings, Particle, Entity, Application };
|
|
114
|
+
export { audio, collision, device, event, loader, level, input, Math, plugin, plugins, utils, save, timer, pool, state, video, Color, Vector2d, Vector3d, ObservableVector2d, ObservableVector3d, Matrix2d, Matrix3d, Polygon, Line, Ellipse, Point, Rect, RoundRect, Tween, QuadTree, GLShader, Compositor, PrimitiveCompositor, QuadCompositor, Renderer, WebGLRenderer, CanvasRenderer, CanvasTexture, TextureAtlas, Renderable, Body, Bounds, Text, BitmapText, BitmapTextData, ColorLayer, ImageLayer, Sprite, NineSliceSprite, UIBaseElement, UITextButton, UISpriteElement, Collectable, Trigger, Light2d, Draggable, DropTarget, TMXRenderer, TMXOrthogonalRenderer, TMXIsometricRenderer, TMXHexagonalRenderer, TMXStaggeredRenderer, Tile, TMXTileset, TMXTilesetGroup, TMXTileMap, TMXLayer, TMXUtils, Pointer, Stage, Camera2d, Container, World, ParticleEmitter, ParticleEmitterSettings, Particle, Entity, Application };
|
|
@@ -1,48 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
-
* @param {string} input - Base64 encoded and compressed data
|
|
6
|
-
* @param {string} format - compressed data format ("gzip","zlib", "zstd")
|
|
7
|
-
* @returns {Uint32Array} Decoded and decompress data
|
|
2
|
+
* set the function used to inflate gzip/zlib data
|
|
3
|
+
* @memberof TMXUtils
|
|
4
|
+
* @param {Func} fn - inflate function
|
|
8
5
|
*/
|
|
9
|
-
export function
|
|
6
|
+
export function setInflateFunction(fn: Func): void;
|
|
10
7
|
/**
|
|
11
|
-
* Decode a
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
* @param
|
|
8
|
+
* Decode a encoded array into a binary array
|
|
9
|
+
* @memberof TMXUtils
|
|
10
|
+
* @param {string} data - data to be decoded
|
|
11
|
+
* @param {string} [encoding="none"] - data encoding ("csv", "base64", "xml")
|
|
15
12
|
* @returns {number[]} Decoded data
|
|
16
13
|
*/
|
|
17
|
-
export function
|
|
18
|
-
/**
|
|
19
|
-
* Decode a base64 encoded string into a byte array
|
|
20
|
-
* @ignore
|
|
21
|
-
* @name decodeBase64AsArray
|
|
22
|
-
* @param {string} input - Base64 encoded data
|
|
23
|
-
* @param {number} [bytes] - number of bytes per array entry
|
|
24
|
-
* @returns {Uint32Array} Decoded data
|
|
25
|
-
*/
|
|
26
|
-
export function decodeBase64AsArray(input: string, bytes?: number | undefined): Uint32Array;
|
|
27
|
-
/**
|
|
28
|
-
* Decode the given data
|
|
29
|
-
* @ignore
|
|
30
|
-
*/
|
|
31
|
-
export function decode(data: any, encoding: any, compression: any): any;
|
|
32
|
-
/**
|
|
33
|
-
* Normalize TMX format to Tiled JSON format
|
|
34
|
-
* @ignore
|
|
35
|
-
*/
|
|
36
|
-
export function normalize(obj: any, item: any): void;
|
|
14
|
+
export function decode(data: string, encoding?: string | undefined, compression: any): number[];
|
|
37
15
|
/**
|
|
38
16
|
* Parse a XML TMX object and returns the corresponding javascript object
|
|
39
|
-
* @
|
|
17
|
+
* @memberof TMXUtils
|
|
18
|
+
* @param {Document} xml - XML TMX object
|
|
19
|
+
* @returns {object} Javascript object
|
|
40
20
|
*/
|
|
41
|
-
export function parse(xml:
|
|
42
|
-
text: string;
|
|
43
|
-
};
|
|
21
|
+
export function parse(xml: Document): object;
|
|
44
22
|
/**
|
|
45
23
|
* Apply TMX Properties to the given object
|
|
46
|
-
* @
|
|
24
|
+
* @memberof TMXUtils
|
|
25
|
+
* @param {object} obj - object to apply the properties to
|
|
26
|
+
* @param {object} data - TMX data object
|
|
27
|
+
* @returns {object} obj
|
|
47
28
|
*/
|
|
48
|
-
export function applyTMXProperties(obj:
|
|
29
|
+
export function applyTMXProperties(obj: object, data: object): object;
|
|
@@ -204,6 +204,7 @@ export default class Renderable extends Rect {
|
|
|
204
204
|
y: boolean;
|
|
205
205
|
};
|
|
206
206
|
_inViewport: boolean;
|
|
207
|
+
_tint: object;
|
|
207
208
|
/**
|
|
208
209
|
* Whether the renderable object is floating (i.e. used screen coordinates), or contained in a floating parent container
|
|
209
210
|
* @see Renderable#floating
|
|
@@ -222,7 +223,6 @@ export default class Renderable extends Rect {
|
|
|
222
223
|
* this.tint.setColor(255, 255, 255);
|
|
223
224
|
*/
|
|
224
225
|
get tint(): Color;
|
|
225
|
-
_tint: object | undefined;
|
|
226
226
|
set inViewport(arg: boolean);
|
|
227
227
|
/**
|
|
228
228
|
* Whether the renderable object is visible and within the viewport
|
|
@@ -411,4 +411,3 @@ export default class Renderable extends Rect {
|
|
|
411
411
|
import Rect from "./../geometries/rectangle.js";
|
|
412
412
|
import ObservableVector3d from "./../math/observable_vector3.js";
|
|
413
413
|
import ObservableVector2d from "./../math/observable_vector2.js";
|
|
414
|
-
import Color from "./../math/color.js";
|
|
@@ -86,9 +86,10 @@ export default class Stage {
|
|
|
86
86
|
* @name draw
|
|
87
87
|
* @memberof Stage
|
|
88
88
|
* @ignore
|
|
89
|
-
* @param {
|
|
89
|
+
* @param {Renderer} renderer - the renderer object to draw with
|
|
90
|
+
* @param {World} world - the world object to draw
|
|
90
91
|
*/
|
|
91
|
-
draw(renderer:
|
|
92
|
+
draw(renderer: Renderer, world: World): void;
|
|
92
93
|
/**
|
|
93
94
|
* destroy function
|
|
94
95
|
* @ignore
|
|
@@ -63,6 +63,16 @@ export const DOM_READY: string;
|
|
|
63
63
|
* @see event.on
|
|
64
64
|
*/
|
|
65
65
|
export const BOOT: string;
|
|
66
|
+
/**
|
|
67
|
+
* event generated when the system update the engine and the renderer by one step
|
|
68
|
+
* @public
|
|
69
|
+
* @constant
|
|
70
|
+
* @type {string}
|
|
71
|
+
* @name TICK
|
|
72
|
+
* @memberof event
|
|
73
|
+
* @see event.on
|
|
74
|
+
*/
|
|
75
|
+
export const TICK: string;
|
|
66
76
|
/**
|
|
67
77
|
* event when the game is paused <br>
|
|
68
78
|
* Data passed : none <br>
|
|
@@ -117,6 +127,16 @@ export const STATE_RESTART: string;
|
|
|
117
127
|
* @see event.on
|
|
118
128
|
*/
|
|
119
129
|
export const STATE_CHANGE: string;
|
|
130
|
+
/**
|
|
131
|
+
* event for when a stage is resetted
|
|
132
|
+
* @public
|
|
133
|
+
* @constant
|
|
134
|
+
* @type {string}
|
|
135
|
+
* @name STAGE_RESET
|
|
136
|
+
* @memberof event
|
|
137
|
+
* @see event.on
|
|
138
|
+
*/
|
|
139
|
+
export const STAGE_RESET: string;
|
|
120
140
|
/**
|
|
121
141
|
* event for when the video is initialized<br>
|
|
122
142
|
* Data passed : none <br>
|
|
@@ -4,29 +4,6 @@
|
|
|
4
4
|
* @augments Renderer
|
|
5
5
|
*/
|
|
6
6
|
export default class CanvasRenderer 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.transparent=false] - Whether to enable transparency on the canvas (performance hit when enabled)
|
|
14
|
-
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel renderering (performance hit when enabled)
|
|
15
|
-
* @param {boolean} [options.textureSeamFix=true] - enable the texture seam fix when rendering Tile when antiAlias is off for the canvasRenderer
|
|
16
|
-
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
17
|
-
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
18
|
-
*/
|
|
19
|
-
constructor(options: {
|
|
20
|
-
width: number;
|
|
21
|
-
height: number;
|
|
22
|
-
canvas?: HTMLCanvasElement | undefined;
|
|
23
|
-
antiAlias?: boolean | undefined;
|
|
24
|
-
transparent?: boolean | undefined;
|
|
25
|
-
subPixel?: boolean | undefined;
|
|
26
|
-
textureSeamFix?: boolean | undefined;
|
|
27
|
-
zoomX?: number | undefined;
|
|
28
|
-
zoomY?: number | undefined;
|
|
29
|
-
});
|
|
30
7
|
context: CanvasRenderingContext2D;
|
|
31
8
|
cache: TextureCache;
|
|
32
9
|
/**
|
|
@@ -4,36 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export default class Renderer {
|
|
6
6
|
/**
|
|
7
|
-
* @param {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* @param {HTMLCanvasElement} [options.canvas] - The html canvas to draw to on screen
|
|
11
|
-
* @param {boolean} [options.antiAlias=false] - Whether to enable anti-aliasing, use false (default) for a pixelated effect.
|
|
12
|
-
* @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.
|
|
13
|
-
* @param {boolean} [options.transparent=false] - Whether to enable transparency on the canvas
|
|
14
|
-
* @param {boolean} [options.premultipliedAlpha=true] - in WebGL, whether the renderer will assume that colors have premultiplied alpha when canvas transparency is enabled
|
|
15
|
-
* @param {boolean} [options.blendMode="normal"] - the default blend mode to use ("normal", "multiply")
|
|
16
|
-
* @param {boolean} [options.depthBuffer="sorting"] - ~Experimental~ the default method to sort object on the z axis in WebGL ("sorting", "z-buffer")
|
|
17
|
-
* @param {boolean} [options.subPixel=false] - Whether to enable subpixel rendering (performance hit when enabled)
|
|
18
|
-
* @param {boolean} [options.verbose=false] - Enable the verbose mode that provides additional details as to what the renderer is doing
|
|
19
|
-
* @param {number} [options.zoomX=width] - The actual width of the canvas with scaling applied
|
|
20
|
-
* @param {number} [options.zoomY=height] - The actual height of the canvas with scaling applied
|
|
21
|
-
*/
|
|
22
|
-
constructor(options: {
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
canvas?: HTMLCanvasElement | undefined;
|
|
26
|
-
antiAlias?: boolean | undefined;
|
|
27
|
-
failIfMajorPerformanceCaveat?: boolean | undefined;
|
|
28
|
-
transparent?: boolean | undefined;
|
|
29
|
-
premultipliedAlpha?: boolean | undefined;
|
|
30
|
-
blendMode?: boolean | undefined;
|
|
31
|
-
depthBuffer?: boolean | undefined;
|
|
32
|
-
subPixel?: boolean | undefined;
|
|
33
|
-
verbose?: boolean | undefined;
|
|
34
|
-
zoomX?: number | undefined;
|
|
35
|
-
zoomY?: number | undefined;
|
|
36
|
-
});
|
|
7
|
+
* @param {Application.Settings} [options] - optional parameters for the renderer
|
|
8
|
+
*/
|
|
9
|
+
constructor(options?: any);
|
|
37
10
|
/**
|
|
38
11
|
* The given constructor options
|
|
39
12
|
* @public
|
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Initialize the "video" system (create a canvas based on the given arguments, and the related renderer). <br>
|
|
3
|
-
* melonJS support various scaling mode, that can be enabled <u>once the scale option is set to <b>`auto`</b></u> : <br>
|
|
4
|
-
* - <i><b>`fit`</b></i> : Letterboxed; content is scaled to design aspect ratio <br>
|
|
5
|
-
* <center><img src="images/scale-fit.png"/></center><br>
|
|
6
|
-
* - <i><b>`fill-min`</b></i> : Canvas is resized to fit minimum design resolution; content is scaled to design aspect ratio <br>
|
|
7
|
-
* <center><img src="images/scale-fill-min.png"/></center><br>
|
|
8
|
-
* - <i><b>`fill-max`</b></i> : Canvas is resized to fit maximum design resolution; content is scaled to design aspect ratio <br>
|
|
9
|
-
* <center><img src="images/scale-fill-max.png"/></center><br>
|
|
10
|
-
* - <i><b>`flex`</b><</i> : Canvas width & height is resized to fit; content is scaled to design aspect ratio <br>
|
|
11
|
-
* <center><img src="images/scale-flex.png"/></center><br>
|
|
12
|
-
* - <i><b>`flex-width`</b></i> : Canvas width is resized to fit; content is scaled to design aspect ratio <br>
|
|
13
|
-
* <center><img src="images/scale-flex-width.png"/></center><br>
|
|
14
|
-
* - <i><b>`flex-height`</b></i> : Canvas height is resized to fit; content is scaled to design aspect ratio <br>
|
|
15
|
-
* <center><img src="images/scale-flex-height.png"/></center><br>
|
|
16
|
-
* - <i><b>`stretch`</b></i> : Canvas is resized to fit; content is scaled to screen aspect ratio
|
|
17
|
-
* <center><img src="images/scale-stretch.png"/></center><br>
|
|
18
3
|
* @memberof video
|
|
19
4
|
* @param {number} width - The width of the canvas viewport
|
|
20
5
|
* @param {number} height - The height of the canvas viewport
|
|
21
|
-
* @param {
|
|
22
|
-
* @param {string|HTMLElement} [options.parent=document.body] - the DOM parent element to hold the canvas in the HTML file
|
|
23
|
-
* @param {number|Renderer} [options.renderer=video.AUTO] - renderer to use (me.video.CANVAS, me.video.WEBGL, me.video.AUTO), or a custom renderer class
|
|
24
|
-
* @param {number|string} [options.scale=1.0] - enable scaling of the canvas ('auto' for automatic scaling)
|
|
25
|
-
* @param {string} [options.scaleMethod="fit"] - screen scaling modes ('fit','fill-min','fill-max','flex','flex-width','flex-height','stretch')
|
|
26
|
-
* @param {boolean} [options.preferWebGL1=false] - if true the renderer will only use WebGL 1
|
|
27
|
-
* @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.
|
|
28
|
-
* @param {boolean} [options.transparent=false] - whether to allow transparent pixels in the front buffer (screen).
|
|
29
|
-
* @param {boolean} [options.antiAlias=false] - whether to enable or not video scaling interpolation
|
|
30
|
-
* @param {boolean} [options.consoleHeader=true] - whether to display melonJS version and basic device information in the console
|
|
6
|
+
* @param {Application.Settings} [options] - optional parameters for the renderer
|
|
31
7
|
* @returns {boolean} false if initialization failed (canvas not supported)
|
|
32
8
|
* @example
|
|
33
9
|
* // init the video with a 640x480 canvas
|
|
@@ -38,17 +14,7 @@
|
|
|
38
14
|
* scaleMethod : "fit"
|
|
39
15
|
* });
|
|
40
16
|
*/
|
|
41
|
-
export function init(width: number, height: number, options?:
|
|
42
|
-
parent?: string | HTMLElement | undefined;
|
|
43
|
-
renderer?: number | Renderer;
|
|
44
|
-
scale?: string | number | undefined;
|
|
45
|
-
scaleMethod?: string | undefined;
|
|
46
|
-
preferWebGL1?: boolean | undefined;
|
|
47
|
-
powerPreference?: string | undefined;
|
|
48
|
-
transparent?: boolean | undefined;
|
|
49
|
-
antiAlias?: boolean | undefined;
|
|
50
|
-
consoleHeader?: boolean | undefined;
|
|
51
|
-
} | undefined): boolean;
|
|
17
|
+
export function init(width: number, height: number, options?: any): boolean;
|
|
52
18
|
/**
|
|
53
19
|
* Create and return a new Canvas element
|
|
54
20
|
* @memberof video
|
|
@@ -64,30 +30,10 @@ export function createCanvas(width: number, height: number, returnOffscreenCanva
|
|
|
64
30
|
* @returns {HTMLElement}
|
|
65
31
|
*/
|
|
66
32
|
export function getParent(): HTMLElement;
|
|
67
|
-
/**
|
|
68
|
-
* @namespace video
|
|
69
|
-
*/
|
|
70
|
-
/**
|
|
71
|
-
* Select the HTML5 Canvas renderer
|
|
72
|
-
* @memberof video
|
|
73
|
-
* @static
|
|
74
|
-
*/
|
|
75
|
-
export const CANVAS: number;
|
|
76
|
-
/**
|
|
77
|
-
* Select the WebGL renderer
|
|
78
|
-
* @memberof video
|
|
79
|
-
* @static
|
|
80
|
-
*/
|
|
81
|
-
export const WEBGL: number;
|
|
82
|
-
/**
|
|
83
|
-
* Auto-select the renderer (Attempt WebGL first, with fallback to Canvas)
|
|
84
|
-
* @memberof video
|
|
85
|
-
* @static
|
|
86
|
-
*/
|
|
87
|
-
export const AUTO: number;
|
|
88
33
|
/**
|
|
89
34
|
* A reference to the active Canvas or WebGL active renderer renderer
|
|
90
35
|
* @memberof video
|
|
91
36
|
* @type {CanvasRenderer|WebGLRenderer}
|
|
92
37
|
*/
|
|
93
38
|
export let renderer: CanvasRenderer | WebGLRenderer;
|
|
39
|
+
export { CANVAS, WEBGL, AUTO } from "../const";
|
|
@@ -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,7 +79,7 @@ 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
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "melonjs",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.3.0",
|
|
4
4
|
"description": "melonJS Game Engine",
|
|
5
5
|
"homepage": "http://www.melonjs.org/",
|
|
6
6
|
"type": "module",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@babel/plugin-syntax-import-assertions": "^7.20.0",
|
|
64
64
|
"@fastify/static": "^6.10.1",
|
|
65
65
|
"@melonjs/webdoc-theme": "^1.1.1",
|
|
66
|
-
"@rollup/plugin-commonjs": "^
|
|
66
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
67
67
|
"@rollup/plugin-image": "^3.0.2",
|
|
68
68
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
69
69
|
"@rollup/plugin-replace": "^5.0.2",
|
|
@@ -71,18 +71,18 @@
|
|
|
71
71
|
"chromedriver": "^113.0.0",
|
|
72
72
|
"cross-env": "^7.0.3",
|
|
73
73
|
"del-cli": "^5.0.0",
|
|
74
|
-
"eslint": "^8.
|
|
75
|
-
"eslint-plugin-jsdoc": "^44.2.
|
|
74
|
+
"eslint": "^8.41.0",
|
|
75
|
+
"eslint-plugin-jsdoc": "^44.2.4",
|
|
76
76
|
"expect": "^29.5.0",
|
|
77
77
|
"expect-mocha-image-snapshot": "^3.0.13",
|
|
78
78
|
"fastify": "^4.17.0",
|
|
79
79
|
"mocha": "^10.2.0",
|
|
80
80
|
"npm-self-link": "^1.1.7",
|
|
81
|
-
"puppeteer": "^20.
|
|
82
|
-
"rollup": "^3.
|
|
81
|
+
"puppeteer": "^20.3.0",
|
|
82
|
+
"rollup": "^3.23.0",
|
|
83
83
|
"rollup-plugin-bundle-size": "^1.0.3",
|
|
84
84
|
"rollup-plugin-string": "^3.0.0",
|
|
85
|
-
"terser": "^5.17.
|
|
85
|
+
"terser": "^5.17.5",
|
|
86
86
|
"typescript": "^5.0.4"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
@@ -21,17 +21,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
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}) {
|
|
@@ -166,6 +156,12 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
166
156
|
this.settings.zoomX = width * this.settings.scale;
|
|
167
157
|
this.settings.zoomY = height * this.settings.scale;
|
|
168
158
|
|
|
159
|
+
// identify parent element and/or the html target for resizing
|
|
160
|
+
this.parentElement = device.getElement(this.settings.parent);
|
|
161
|
+
if (typeof this.settings.scaleTarget !== "undefined" ) {
|
|
162
|
+
this.settings.scaleTarget = device.getElement(this.settings.scaleTarget);
|
|
163
|
+
}
|
|
164
|
+
|
|
169
165
|
if (typeof this.settings.renderer === "number") {
|
|
170
166
|
switch (this.settings.renderer) {
|
|
171
167
|
case AUTO:
|
|
@@ -187,7 +183,6 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
187
183
|
event.on(event.WINDOW_ONORIENTATION_CHANGE, () => onresize(this), this);
|
|
188
184
|
|
|
189
185
|
// add our canvas (default to document.body if settings.parent is undefined)
|
|
190
|
-
this.parentElement = device.getElement(this.settings.parent);
|
|
191
186
|
this.parentElement.appendChild(this.renderer.getCanvas());
|
|
192
187
|
|
|
193
188
|
// Mobile browser hacks
|
|
@@ -226,6 +221,16 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
226
221
|
this.isInitialized = true;
|
|
227
222
|
|
|
228
223
|
event.emit(event.GAME_INIT, this);
|
|
224
|
+
event.on(event.STATE_CHANGE, this.repaint, this);
|
|
225
|
+
event.on(event.STATE_RESTART, this.repaint, this);
|
|
226
|
+
event.on(event.STATE_RESUME, this.repaint, this);
|
|
227
|
+
event.on(event.STAGE_RESET, this.reset, this);
|
|
228
|
+
event.on(event.TICK, (time) => {
|
|
229
|
+
// update all game objects
|
|
230
|
+
this.update(time);
|
|
231
|
+
// render all game objects
|
|
232
|
+
this.draw();
|
|
233
|
+
}, this);
|
|
229
234
|
}
|
|
230
235
|
|
|
231
236
|
/**
|
|
@@ -306,9 +311,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
306
311
|
/**
|
|
307
312
|
* update all objects related to this game active scene/stage
|
|
308
313
|
* @param {number} time - current timestamp as provided by the RAF callback
|
|
309
|
-
* @param {Stage} stage - the current stage
|
|
310
314
|
*/
|
|
311
|
-
update(time
|
|
315
|
+
update(time) {
|
|
312
316
|
// handle frame skipping if required
|
|
313
317
|
if ((++this.frameCounter % this.frameRate) === 0) {
|
|
314
318
|
// reset the frame counter
|
|
@@ -332,7 +336,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
332
336
|
}
|
|
333
337
|
|
|
334
338
|
// update all objects (and pass the elapsed time since last frame)
|
|
335
|
-
this.isDirty =
|
|
339
|
+
this.isDirty = this.world.update(this.updateDelta);
|
|
340
|
+
this.isDirty = state.current().update(this.updateDelta) || this.isDirty;
|
|
336
341
|
|
|
337
342
|
this.lastUpdate = globalThis.performance.now();
|
|
338
343
|
this.updateAverageDelta = this.lastUpdate - this.lastUpdateStart;
|
|
@@ -351,9 +356,8 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
351
356
|
|
|
352
357
|
/**
|
|
353
358
|
* draw the active scene/stage associated to this game
|
|
354
|
-
* @param {Stage} stage - the current stage
|
|
355
359
|
*/
|
|
356
|
-
draw(
|
|
360
|
+
draw() {
|
|
357
361
|
if (this.renderer.isContextValid === true && (this.isDirty || this.isAlwaysDirty)) {
|
|
358
362
|
// publish notification
|
|
359
363
|
event.emit(event.GAME_BEFORE_DRAW, globalThis.performance.now());
|
|
@@ -362,7 +366,7 @@ import { CANVAS, WEBGL, AUTO } from "../const.js";
|
|
|
362
366
|
this.renderer.clear();
|
|
363
367
|
|
|
364
368
|
// render the stage
|
|
365
|
-
|
|
369
|
+
state.current().draw(this.renderer, this.world);
|
|
366
370
|
|
|
367
371
|
// set back to flag
|
|
368
372
|
this.isDirty = false;
|