melonjs 14.4.0 → 15.0.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/LICENSE.md +1 -1
- package/README.md +13 -57
- 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 +1 -1
- package/dist/melonjs.mjs/application/header.js +1 -1
- package/dist/melonjs.mjs/application/resize.js +1 -1
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +5 -7
- package/dist/melonjs.mjs/camera/camera2d.js +1 -1
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +43 -9
- package/dist/melonjs.mjs/geometries/ellipse.js +2 -3
- package/dist/melonjs.mjs/geometries/line.js +1 -1
- package/dist/melonjs.mjs/geometries/path2d.js +20 -44
- package/dist/melonjs.mjs/geometries/point.js +1 -6
- package/dist/melonjs.mjs/geometries/poly.js +2 -5
- package/dist/melonjs.mjs/geometries/rectangle.js +13 -9
- package/dist/melonjs.mjs/geometries/roundrect.js +1 -1
- package/dist/melonjs.mjs/index.js +10 -6
- package/dist/melonjs.mjs/input/gamepad.js +10 -16
- 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 +3 -17
- 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 +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +1 -1
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +1 -8
- 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 +8 -4
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +5 -5
- 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/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 +24 -0
- package/dist/melonjs.mjs/loader/loader.js +331 -716
- package/dist/melonjs.mjs/loader/loadingscreen.js +4 -4
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +281 -0
- package/dist/melonjs.mjs/loader/settings.js +91 -0
- package/dist/melonjs.mjs/math/color.js +9 -8
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +7 -9
- package/dist/melonjs.mjs/math/matrix3.js +18 -21
- package/dist/melonjs.mjs/math/observable_vector2.js +3 -3
- package/dist/melonjs.mjs/math/observable_vector3.js +3 -4
- package/dist/melonjs.mjs/math/vector2.js +3 -3
- package/dist/melonjs.mjs/math/vector3.js +3 -4
- 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 +3 -3
- 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 +18 -14
- package/dist/melonjs.mjs/physics/bounds.js +18 -70
- 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 +25 -19
- package/dist/melonjs.mjs/renderable/dragndrop.js +1 -1
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -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 +148 -105
- package/dist/melonjs.mjs/renderable/sprite.js +33 -54
- 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 -3
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +2 -2
- package/dist/melonjs.mjs/system/device.js +2 -2
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +1 -1
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +8 -18
- 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 +66 -8
- 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 +56 -86
- package/dist/melonjs.mjs/text/textmetrics.js +1 -1
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- 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 +2 -2
- package/dist/melonjs.mjs/utils/utils.js +2 -4
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +7 -11
- package/dist/melonjs.mjs/video/renderer.js +2 -13
- package/dist/melonjs.mjs/video/texture/atlas.js +12 -17
- package/dist/melonjs.mjs/video/texture/cache.js +3 -3
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +235 -0
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +249 -0
- package/dist/melonjs.mjs/video/webgl/{webgl_compositor.js → compositors/webgl_compositor.js} +20 -205
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/shaders/quad.frag.js +1 -1
- package/dist/melonjs.mjs/video/webgl/shaders/quad.vert.js +2 -2
- 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 +139 -149
- package/dist/melonjs.module.js +26320 -26376
- package/dist/types/entity/entity.d.ts +3 -3
- package/dist/types/geometries/path2d.d.ts +5 -31
- package/dist/types/geometries/point.d.ts +2 -7
- package/dist/types/geometries/poly.d.ts +0 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/loader/cache.d.ts +7 -0
- package/dist/types/loader/loader.d.ts +166 -181
- package/dist/types/loader/parser.d.ts +41 -0
- package/dist/types/loader/settings.d.ts +57 -0
- package/dist/types/particles/emitter.d.ts +4 -4
- package/dist/types/physics/bounds.d.ts +29 -84
- package/dist/types/renderable/container.d.ts +0 -11
- package/dist/types/renderable/renderable.d.ts +43 -31
- package/dist/types/renderable/sprite.d.ts +3 -3
- package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
- package/dist/types/state/state.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +2 -2
- package/dist/types/text/text.d.ts +6 -20
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/video/canvas/canvas_renderer.d.ts +0 -5
- package/dist/types/video/renderer.d.ts +1 -5
- package/dist/types/video/webgl/buffer/vertex.d.ts +3 -3
- package/dist/types/video/webgl/compositors/compositor.d.ts +107 -0
- package/dist/types/video/webgl/compositors/primitive_compositor.d.ts +22 -0
- package/dist/types/video/webgl/compositors/quad_compositor.d.ts +72 -0
- package/dist/types/video/webgl/compositors/webgl_compositor.d.ts +86 -0
- package/dist/types/video/webgl/webgl_compositor.d.ts +2 -3
- package/dist/types/video/webgl/webgl_renderer.d.ts +34 -28
- package/package.json +18 -18
- package/src/audio/audio.js +4 -6
- package/src/entity/entity.js +42 -8
- package/src/geometries/ellipse.js +1 -2
- package/src/geometries/path2d.js +19 -43
- package/src/geometries/point.js +0 -5
- package/src/geometries/poly.js +1 -4
- package/src/geometries/rectangle.js +12 -8
- package/src/index.js +7 -3
- package/src/input/gamepad.js +9 -15
- package/src/input/pointerevent.js +1 -15
- package/src/level/level.js +2 -2
- package/src/level/tiled/TMXLayer.js +0 -7
- package/src/level/tiled/TMXTileMap.js +7 -3
- package/src/level/tiled/TMXTileset.js +4 -4
- package/src/loader/cache.js +16 -0
- package/src/loader/loader.js +339 -711
- package/src/loader/loadingscreen.js +3 -3
- package/src/loader/parser.js +279 -0
- package/src/loader/settings.js +85 -0
- package/src/math/color.js +8 -7
- package/src/math/matrix2.js +6 -8
- package/src/math/matrix3.js +17 -20
- package/src/math/observable_vector2.js +2 -2
- package/src/math/observable_vector3.js +2 -3
- package/src/math/vector2.js +2 -2
- package/src/math/vector3.js +2 -3
- package/src/particles/emitter.js +2 -2
- package/src/physics/body.js +17 -13
- package/src/physics/bounds.js +17 -69
- package/src/polyfill/index.js +0 -2
- package/src/renderable/container.js +24 -18
- package/src/renderable/imagelayer.js +6 -0
- package/src/renderable/renderable.js +147 -104
- package/src/renderable/sprite.js +32 -53
- package/src/renderable/ui/uitextbutton.js +0 -2
- package/src/state/state.js +1 -1
- package/src/system/device.js +1 -1
- package/src/system/pooling.js +7 -17
- package/src/text/bitmaptext.js +65 -7
- package/src/text/text.js +55 -85
- package/src/text/textstyle.js +3 -5
- package/src/utils/string.js +1 -1
- package/src/utils/utils.js +1 -3
- package/src/video/canvas/canvas_renderer.js +5 -9
- package/src/video/renderer.js +0 -11
- package/src/video/texture/atlas.js +11 -16
- package/src/video/texture/cache.js +2 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +20 -16
- package/src/video/webgl/compositors/compositor.js +226 -0
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/quad_compositor.js +240 -0
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/webgl_renderer.js +137 -147
- package/dist/melonjs.mjs/_virtual/make-built-in.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-define-property.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-descriptor.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-names.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-get-own-property-symbols.js +0 -10
- package/dist/melonjs.mjs/_virtual/object-property-is-enumerable.js +0 -10
- package/dist/melonjs.mjs/_virtual/shared.js +0 -10
- package/dist/melonjs.mjs/game.js +0 -29
- package/dist/melonjs.mjs/polyfill/console.js +0 -18
- package/dist/melonjs.mjs/polyfill/performance.js +0 -27
- package/dist/melonjs.mjs/polyfill/requestAnimationFrame.js +0 -46
- package/dist/melonjs.mjs/polyfill/roundrect.js +0 -242
- package/dist/melonjs.mjs/renderable/re_container.js +0 -1016
- package/dist/melonjs.mjs/video/utils/resize.js +0 -116
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
- package/src/video/webgl/webgl_compositor.js +0 -486
|
@@ -4,7 +4,7 @@ import * as event from "./../system/event.js";
|
|
|
4
4
|
import Sprite from "./../renderable/sprite.js";
|
|
5
5
|
import Renderable from "./../renderable/renderable.js";
|
|
6
6
|
import Stage from "./../state/stage.js";
|
|
7
|
-
import
|
|
7
|
+
import { load, unload } from "./loader.js";
|
|
8
8
|
import logo_url from "./melonjs_logo.png";
|
|
9
9
|
|
|
10
10
|
|
|
@@ -86,7 +86,7 @@ class DefaultLoadingScreen extends Stage {
|
|
|
86
86
|
), 1);
|
|
87
87
|
|
|
88
88
|
// load the melonJS logo
|
|
89
|
-
|
|
89
|
+
load({name: "melonjs_logo", type: "image", src: logo_url}, () => {
|
|
90
90
|
// melonJS logo
|
|
91
91
|
game.world.addChild(new Sprite(
|
|
92
92
|
renderer.getWidth() / 2,
|
|
@@ -105,7 +105,7 @@ class DefaultLoadingScreen extends Stage {
|
|
|
105
105
|
*/
|
|
106
106
|
onDestroyEvent() {
|
|
107
107
|
// cancel the callback
|
|
108
|
-
|
|
108
|
+
unload({name: "melonjs_logo", type:"image"});
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import * as fileUtil from "../utils/file.js";
|
|
2
|
+
import { ua } from "../system/platform.js";
|
|
3
|
+
import level from "../level/level.js";
|
|
4
|
+
import * as TMXUtils from "../level/tiled/TMXUtils.js";
|
|
5
|
+
import { isDataUrl } from "../utils/string.js";
|
|
6
|
+
import { imgList, tmxList, binList, jsonList } from "./cache.js";
|
|
7
|
+
import { crossOrigin, nocache, withCredentials } from "./settings.js";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* load Images
|
|
12
|
+
* @example
|
|
13
|
+
* preloadImages([
|
|
14
|
+
* { name : 'image1', src : 'images/image1.png'},
|
|
15
|
+
* { name : 'image2', src : 'images/image2.png'},
|
|
16
|
+
* { name : 'image3', src : 'images/image3.png'},
|
|
17
|
+
* { name : 'image4', src : 'images/image4.png'}
|
|
18
|
+
* ]);
|
|
19
|
+
* @ignore
|
|
20
|
+
*/
|
|
21
|
+
export function preloadImage(img, onload, onerror) {
|
|
22
|
+
// create new Image object and add to list
|
|
23
|
+
imgList[img.name] = new Image();
|
|
24
|
+
if (typeof onload === "function") {
|
|
25
|
+
imgList[img.name].onload = onload;
|
|
26
|
+
}
|
|
27
|
+
if (typeof onerror === "function") {
|
|
28
|
+
imgList[img.name].onerror = onerror;
|
|
29
|
+
}
|
|
30
|
+
if (typeof (crossOrigin) === "string") {
|
|
31
|
+
imgList[img.name].crossOrigin = crossOrigin;
|
|
32
|
+
}
|
|
33
|
+
imgList[img.name].src = img.src + nocache;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* load a font face
|
|
38
|
+
* @example
|
|
39
|
+
* preloadFontFace(
|
|
40
|
+
* name: "'kenpixel'", type: "fontface", src: "url('data/font/kenvector_future.woff2')"
|
|
41
|
+
* ]);
|
|
42
|
+
* @ignore
|
|
43
|
+
*/
|
|
44
|
+
export function preloadFontFace(data, onload, onerror) {
|
|
45
|
+
|
|
46
|
+
if (isDataUrl(data.src) === true) {
|
|
47
|
+
// make sure it in the `url(data:[<mediatype>][;base64],<data>)` format as expected by FontFace
|
|
48
|
+
if (!data.src.startsWith("url(")) {
|
|
49
|
+
data.src = "url(" + data.src + ")";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var font = new FontFace(data.name, data.src);
|
|
54
|
+
|
|
55
|
+
// loading promise
|
|
56
|
+
font.load().then(() => {
|
|
57
|
+
// apply the font after the font has finished downloading
|
|
58
|
+
document.fonts.add(font);
|
|
59
|
+
document.body.style.fontFamily = data.name;
|
|
60
|
+
if (typeof onload === "function") {
|
|
61
|
+
// onloaded callback
|
|
62
|
+
onload();
|
|
63
|
+
}
|
|
64
|
+
}, () => {
|
|
65
|
+
if (typeof onerror === "function") {
|
|
66
|
+
// rejected
|
|
67
|
+
onerror(data.name);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* preload TMX files
|
|
74
|
+
* @ignore
|
|
75
|
+
*/
|
|
76
|
+
export function preloadTMX(tmxData, onload, onerror) {
|
|
77
|
+
/**
|
|
78
|
+
* @ignore
|
|
79
|
+
*/
|
|
80
|
+
function addToTMXList(data) {
|
|
81
|
+
// set the TMX content
|
|
82
|
+
tmxList[tmxData.name] = data;
|
|
83
|
+
|
|
84
|
+
// add the tmx to the level manager
|
|
85
|
+
if (tmxData.type === "tmx") {
|
|
86
|
+
level.add(tmxData.type, tmxData.name);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
//if the data is in the tmxData object, don't get it via a XMLHTTPRequest
|
|
92
|
+
if (tmxData.data) {
|
|
93
|
+
addToTMXList(tmxData.data);
|
|
94
|
+
if (typeof onload === "function") {
|
|
95
|
+
onload();
|
|
96
|
+
}
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var xmlhttp = new XMLHttpRequest();
|
|
101
|
+
// check the data format ('tmx', 'json')
|
|
102
|
+
var format = fileUtil.getExtension(tmxData.src);
|
|
103
|
+
|
|
104
|
+
if (xmlhttp.overrideMimeType) {
|
|
105
|
+
if (format === "json") {
|
|
106
|
+
xmlhttp.overrideMimeType("application/json");
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
xmlhttp.overrideMimeType("text/xml");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
xmlhttp.open("GET", tmxData.src + nocache, true);
|
|
114
|
+
xmlhttp.withCredentials = withCredentials;
|
|
115
|
+
// set the callbacks
|
|
116
|
+
xmlhttp.ontimeout = onerror;
|
|
117
|
+
xmlhttp.onreadystatechange = function () {
|
|
118
|
+
if (xmlhttp.readyState === 4) {
|
|
119
|
+
// status = 0 when file protocol is used, or cross-domain origin,
|
|
120
|
+
// (With Chrome use "--allow-file-access-from-files --disable-web-security")
|
|
121
|
+
if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
|
|
122
|
+
var result = null;
|
|
123
|
+
|
|
124
|
+
// parse response
|
|
125
|
+
switch (format) {
|
|
126
|
+
case "xml":
|
|
127
|
+
case "tmx":
|
|
128
|
+
case "tsx":
|
|
129
|
+
// ie9 does not fully implement the responseXML
|
|
130
|
+
if (ua.match(/msie/i) || !xmlhttp.responseXML) {
|
|
131
|
+
if (globalThis.DOMParser) {
|
|
132
|
+
// manually create the XML DOM
|
|
133
|
+
result = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");
|
|
134
|
+
} else {
|
|
135
|
+
throw new Error("XML file format loading not supported, use the JSON file format instead");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
result = xmlhttp.responseXML;
|
|
140
|
+
}
|
|
141
|
+
// converts to a JS object
|
|
142
|
+
var data = TMXUtils.parse(result);
|
|
143
|
+
switch (format) {
|
|
144
|
+
case "tmx":
|
|
145
|
+
result = data.map;
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case "tsx":
|
|
149
|
+
result = data.tilesets[0];
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
break;
|
|
154
|
+
|
|
155
|
+
case "json":
|
|
156
|
+
case "tmj":
|
|
157
|
+
case "tsj":
|
|
158
|
+
result = JSON.parse(xmlhttp.responseText);
|
|
159
|
+
break;
|
|
160
|
+
|
|
161
|
+
default:
|
|
162
|
+
throw new Error("TMX file format " + format + " not supported !");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//set the TMX content
|
|
166
|
+
addToTMXList(result);
|
|
167
|
+
|
|
168
|
+
// fire the callback
|
|
169
|
+
if (typeof onload === "function") {
|
|
170
|
+
onload();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else if (typeof onerror === "function") {
|
|
174
|
+
onerror(tmxData.name);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
// send the request
|
|
179
|
+
xmlhttp.send();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* preload JSON files
|
|
184
|
+
* @ignore
|
|
185
|
+
*/
|
|
186
|
+
export function preloadJSON(data, onload, onerror) {
|
|
187
|
+
var xmlhttp = new XMLHttpRequest();
|
|
188
|
+
|
|
189
|
+
if (xmlhttp.overrideMimeType) {
|
|
190
|
+
xmlhttp.overrideMimeType("application/json");
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
xmlhttp.open("GET", data.src + nocache, true);
|
|
194
|
+
xmlhttp.withCredentials = withCredentials;
|
|
195
|
+
|
|
196
|
+
// set the callbacks
|
|
197
|
+
xmlhttp.ontimeout = onerror;
|
|
198
|
+
xmlhttp.onreadystatechange = function () {
|
|
199
|
+
if (xmlhttp.readyState === 4) {
|
|
200
|
+
// status = 0 when file protocol is used, or cross-domain origin,
|
|
201
|
+
// (With Chrome use "--allow-file-access-from-files --disable-web-security")
|
|
202
|
+
if ((xmlhttp.status === 200) || ((xmlhttp.status === 0) && xmlhttp.responseText)) {
|
|
203
|
+
// get the Texture Packer Atlas content
|
|
204
|
+
jsonList[data.name] = JSON.parse(xmlhttp.responseText);
|
|
205
|
+
if (typeof onload === "function") {
|
|
206
|
+
// fire the callback
|
|
207
|
+
onload();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if (typeof onerror === "function") {
|
|
211
|
+
onerror(data.name);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
// send the request
|
|
216
|
+
xmlhttp.send();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* preload Binary files
|
|
221
|
+
* @ignore
|
|
222
|
+
*/
|
|
223
|
+
export function preloadBinary(data, onload, onerror) {
|
|
224
|
+
var httpReq = new XMLHttpRequest();
|
|
225
|
+
|
|
226
|
+
// load our file
|
|
227
|
+
httpReq.open("GET", data.src + nocache, true);
|
|
228
|
+
httpReq.withCredentials = withCredentials;
|
|
229
|
+
httpReq.responseType = "arraybuffer";
|
|
230
|
+
httpReq.onerror = onerror;
|
|
231
|
+
httpReq.onload = function () {
|
|
232
|
+
var arrayBuffer = httpReq.response;
|
|
233
|
+
if (arrayBuffer) {
|
|
234
|
+
var byteArray = new Uint8Array(arrayBuffer);
|
|
235
|
+
var buffer = [];
|
|
236
|
+
for (var i = 0; i < byteArray.byteLength; i++) {
|
|
237
|
+
buffer[i] = String.fromCharCode(byteArray[i]);
|
|
238
|
+
}
|
|
239
|
+
binList[data.name] = buffer.join("");
|
|
240
|
+
if (typeof onload === "function") {
|
|
241
|
+
// callback
|
|
242
|
+
onload();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
httpReq.send();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* preload Binary files
|
|
252
|
+
* @ignore
|
|
253
|
+
*/
|
|
254
|
+
export function preloadJavascript(data, onload, onerror) {
|
|
255
|
+
var script = document.createElement("script");
|
|
256
|
+
|
|
257
|
+
script.src = data.src;
|
|
258
|
+
script.type = "text/javascript";
|
|
259
|
+
if (typeof (crossOrigin) === "string") {
|
|
260
|
+
script.crossOrigin = crossOrigin;
|
|
261
|
+
}
|
|
262
|
+
script.defer = true;
|
|
263
|
+
|
|
264
|
+
if (typeof onload === "function") {
|
|
265
|
+
script.onload = () => {
|
|
266
|
+
// callback
|
|
267
|
+
onload();
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (typeof onerror === "function") {
|
|
272
|
+
script.onerror = () => {
|
|
273
|
+
// callback
|
|
274
|
+
onerror(data.name);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
document.getElementsByTagName("body")[0].appendChild(script);
|
|
279
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
// to enable/disable caching
|
|
3
|
+
export let nocache = "";
|
|
4
|
+
|
|
5
|
+
// baseURL
|
|
6
|
+
export let baseURL = {};
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* crossOrigin attribute to configure the CORS requests for Image data element.
|
|
11
|
+
* By default (that is, when the attribute is not specified), CORS is not used at all.
|
|
12
|
+
* The "anonymous" keyword means that there will be no exchange of user credentials via cookies,
|
|
13
|
+
* client-side SSL certificates or HTTP authentication as described in the Terminology section of the CORS specification.<br>
|
|
14
|
+
* @type {string}
|
|
15
|
+
* @name crossOrigin
|
|
16
|
+
* @default undefined
|
|
17
|
+
* @memberof loader
|
|
18
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes
|
|
19
|
+
* @example
|
|
20
|
+
* // allow for cross-origin texture loading in WebGL
|
|
21
|
+
* me.loader.crossOrigin = "anonymous";
|
|
22
|
+
*
|
|
23
|
+
* // set all ressources to be loaded
|
|
24
|
+
* me.loader.preload(game.resources, this.loaded.bind(this));
|
|
25
|
+
*/
|
|
26
|
+
export let crossOrigin;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies,
|
|
30
|
+
* authorization headers or TLS client certificates. Setting withCredentials has no effect on same-site requests.
|
|
31
|
+
* @public
|
|
32
|
+
* @type {boolean}
|
|
33
|
+
* @name withCredentials
|
|
34
|
+
* @default false
|
|
35
|
+
* @memberof loader
|
|
36
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials
|
|
37
|
+
* @example
|
|
38
|
+
* // enable withCredentials
|
|
39
|
+
* me.loader.withCredentials = true;
|
|
40
|
+
*
|
|
41
|
+
* // set all ressources to be loaded
|
|
42
|
+
* me.loader.preload(game.resources, this.loaded.bind(this));
|
|
43
|
+
*/
|
|
44
|
+
export let withCredentials = false;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* enable the nocache mechanism
|
|
48
|
+
* @ignore
|
|
49
|
+
*/
|
|
50
|
+
export function setNocache(enable = false) {
|
|
51
|
+
nocache = enable ? "?" + ~~(Math.random() * 10000000) : "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* change the default baseURL for the given asset type.<br>
|
|
56
|
+
* (this will prepend the asset URL and must finish with a '/')
|
|
57
|
+
* @name setBaseURL
|
|
58
|
+
* @memberof loader
|
|
59
|
+
* @public
|
|
60
|
+
* @param {string} type - "*", "audio", binary", "image", "json", "js", "tmx", "tsx"
|
|
61
|
+
* @param {string} [url="./"] - default base URL
|
|
62
|
+
* @example
|
|
63
|
+
* // change the base URL relative address for audio assets
|
|
64
|
+
* me.loader.setBaseURL("audio", "data/audio/");
|
|
65
|
+
* // change the base URL absolute address for all object types
|
|
66
|
+
* me.loader.setBaseURL("*", "http://myurl.com/")
|
|
67
|
+
*/
|
|
68
|
+
export function setBaseURL(type, url) {
|
|
69
|
+
if (type !== "*") {
|
|
70
|
+
baseURL[type] = url;
|
|
71
|
+
} else {
|
|
72
|
+
// "wildcards"
|
|
73
|
+
baseURL["audio"] = url;
|
|
74
|
+
baseURL["binary"] = url;
|
|
75
|
+
baseURL["image"] = url;
|
|
76
|
+
baseURL["json"] = url;
|
|
77
|
+
baseURL["js"] = url;
|
|
78
|
+
baseURL["tmx"] = url;
|
|
79
|
+
baseURL["tsx"] = url;
|
|
80
|
+
// XXX ?
|
|
81
|
+
//baseURL["fontface"] = url;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
package/src/math/color.js
CHANGED
|
@@ -250,8 +250,8 @@ var cssToRGB = new Map();
|
|
|
250
250
|
return this.glArray[3];
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
set alpha(value) {
|
|
254
|
-
this.glArray[3] =
|
|
253
|
+
set alpha(value = 1.0) {
|
|
254
|
+
this.glArray[3] = clamp(+value, 0, 1.0);
|
|
255
255
|
}
|
|
256
256
|
|
|
257
257
|
|
|
@@ -534,12 +534,13 @@ var cssToRGB = new Map();
|
|
|
534
534
|
* @returns {number}
|
|
535
535
|
*/
|
|
536
536
|
toUint32(alpha = 1.0) {
|
|
537
|
-
var
|
|
538
|
-
var ug = this.g & 0xff;
|
|
539
|
-
var ub = this.b & 0xff;
|
|
540
|
-
var ua = (alpha * 255) & 0xff;
|
|
537
|
+
var a = this.glArray;
|
|
541
538
|
|
|
542
|
-
|
|
539
|
+
var ur = (a[0] * 255) & 0xff;
|
|
540
|
+
var ug = (a[1] * 255) & 0xff;
|
|
541
|
+
var ub = (a[2] * 255) & 0xff;
|
|
542
|
+
|
|
543
|
+
return (((alpha * 255) & 0xff) << 24) + (ur << 16) + (ug << 8) + ub;
|
|
543
544
|
}
|
|
544
545
|
|
|
545
546
|
/**
|
package/src/math/matrix2.js
CHANGED
|
@@ -296,15 +296,13 @@ import Matrix3d from "./matrix3.js";
|
|
|
296
296
|
* @param {number} [y=x] - a number representing the ordinate of the scaling vector.
|
|
297
297
|
* @returns {Matrix2d} Reference to this object for method chaining
|
|
298
298
|
*/
|
|
299
|
-
scale(x, y) {
|
|
300
|
-
var a = this.val
|
|
301
|
-
_x = x,
|
|
302
|
-
_y = typeof(y) === "undefined" ? _x : y;
|
|
299
|
+
scale(x, y = x) {
|
|
300
|
+
var a = this.val;
|
|
303
301
|
|
|
304
|
-
a[0] *=
|
|
305
|
-
a[1] *=
|
|
306
|
-
a[3] *=
|
|
307
|
-
a[4] *=
|
|
302
|
+
a[0] *= x;
|
|
303
|
+
a[1] *= x;
|
|
304
|
+
a[3] *= y;
|
|
305
|
+
a[4] *= y;
|
|
308
306
|
|
|
309
307
|
return this;
|
|
310
308
|
}
|
package/src/math/matrix3.js
CHANGED
|
@@ -394,26 +394,23 @@ import { EPSILON } from "./math.js";
|
|
|
394
394
|
* @param {number} [z=0] - a number representing the depth vector
|
|
395
395
|
* @returns {Matrix3d} Reference to this object for method chaining
|
|
396
396
|
*/
|
|
397
|
-
scale(x, y, z) {
|
|
398
|
-
var a = this.val
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
a[
|
|
404
|
-
|
|
405
|
-
a[
|
|
406
|
-
a[
|
|
407
|
-
|
|
408
|
-
a[
|
|
409
|
-
|
|
410
|
-
a[
|
|
411
|
-
a[
|
|
412
|
-
|
|
413
|
-
a[
|
|
414
|
-
a[9] = a[9] * _z;
|
|
415
|
-
a[10] = a[10] * _z;
|
|
416
|
-
a[11] = a[11] * _z;
|
|
397
|
+
scale(x, y = x, z = 0) {
|
|
398
|
+
var a = this.val;
|
|
399
|
+
|
|
400
|
+
a[0] = a[0] * x;
|
|
401
|
+
a[1] = a[1] * x;
|
|
402
|
+
a[2] = a[2] * x;
|
|
403
|
+
a[3] = a[3] * x;
|
|
404
|
+
|
|
405
|
+
a[4] = a[4] * y;
|
|
406
|
+
a[5] = a[5] * y;
|
|
407
|
+
a[6] = a[6] * y;
|
|
408
|
+
a[7] = a[7] * y;
|
|
409
|
+
|
|
410
|
+
a[8] = a[8] * z;
|
|
411
|
+
a[9] = a[9] * z;
|
|
412
|
+
a[10] = a[10] * z;
|
|
413
|
+
a[11] = a[11] * z;
|
|
417
414
|
|
|
418
415
|
return this;
|
|
419
416
|
}
|
|
@@ -156,8 +156,8 @@ import {clamp} from "./math.js";
|
|
|
156
156
|
* @param {number} [y=x]
|
|
157
157
|
* @returns {ObservableVector2d} Reference to this object for method chaining
|
|
158
158
|
*/
|
|
159
|
-
scale(x, y) {
|
|
160
|
-
return this._set(this._x * x, this._y *
|
|
159
|
+
scale(x, y = x) {
|
|
160
|
+
return this._set(this._x * x, this._y * y);
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
/**
|
|
@@ -186,9 +186,8 @@ import pool from "./../system/pooling.js";
|
|
|
186
186
|
* @param {number} [z=1]
|
|
187
187
|
* @returns {ObservableVector3d} Reference to this object for method chaining
|
|
188
188
|
*/
|
|
189
|
-
scale(x, y, z) {
|
|
190
|
-
|
|
191
|
-
return this._set(this._x * x, this._y * y, this._z * (z || 1));
|
|
189
|
+
scale(x, y = x, z = 1) {
|
|
190
|
+
return this._set(this._x * x, this._y * y, this._z * z);
|
|
192
191
|
}
|
|
193
192
|
|
|
194
193
|
/**
|
package/src/math/vector2.js
CHANGED
|
@@ -120,8 +120,8 @@ import pool from "./../system/pooling.js";
|
|
|
120
120
|
* @param {number} [y=x]
|
|
121
121
|
* @returns {Vector2d} Reference to this object for method chaining
|
|
122
122
|
*/
|
|
123
|
-
scale(x, y) {
|
|
124
|
-
return this._set(this.x * x, this.y *
|
|
123
|
+
scale(x, y = x) {
|
|
124
|
+
return this._set(this.x * x, this.y * y);
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
package/src/math/vector3.js
CHANGED
|
@@ -134,9 +134,8 @@ import pool from "./../system/pooling.js";
|
|
|
134
134
|
* @param {number} [z=1]
|
|
135
135
|
* @returns {Vector3d} Reference to this object for method chaining
|
|
136
136
|
*/
|
|
137
|
-
scale(x, y, z) {
|
|
138
|
-
|
|
139
|
-
return this._set(this.x * x, this.y * y, this.z * (z || 1));
|
|
137
|
+
scale(x, y = x, z = 1) {
|
|
138
|
+
return this._set(this.x * x, this.y * y, this.z * z);
|
|
140
139
|
}
|
|
141
140
|
|
|
142
141
|
/**
|
package/src/particles/emitter.js
CHANGED
|
@@ -161,7 +161,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
|
|
|
161
161
|
|
|
162
162
|
/**
|
|
163
163
|
* Launch particles from emitter constantly (e.g. for stream)
|
|
164
|
-
* @param {number} duration -
|
|
164
|
+
* @param {number} [duration] - time that the emitter releases particles in ms
|
|
165
165
|
*/
|
|
166
166
|
streamParticles(duration) {
|
|
167
167
|
this._enabled = true;
|
|
@@ -179,7 +179,7 @@ function createDefaultParticleTexture(w = 8, h = 8) {
|
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
181
|
* Launch all particles from emitter and stop (e.g. for explosion)
|
|
182
|
-
* @param {number} total -
|
|
182
|
+
* @param {number} [total] - number of particles to launch
|
|
183
183
|
*/
|
|
184
184
|
burstParticles(total) {
|
|
185
185
|
this._enabled = true;
|
package/src/physics/body.js
CHANGED
|
@@ -558,20 +558,24 @@ import Point from "../geometries/point.js";
|
|
|
558
558
|
* @returns {Body} Reference to this object for method chaining
|
|
559
559
|
*/
|
|
560
560
|
rotate(angle, v = this.getBounds().center) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
shape.
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
561
|
+
if (angle !== 0) {
|
|
562
|
+
this.bounds.clear();
|
|
563
|
+
this.forEach((shape) => {
|
|
564
|
+
shape.rotate(angle, v);
|
|
565
|
+
this.bounds.addBounds(shape.getBounds());
|
|
566
|
+
/*
|
|
567
|
+
if (!(shape instanceof Ellipse)) {
|
|
568
|
+
// ellipse position is center
|
|
569
|
+
this.bounds.translate(shape.pos);
|
|
570
|
+
}
|
|
571
|
+
*/
|
|
572
|
+
});
|
|
573
|
+
/*
|
|
574
|
+
if (typeof this.onBodyUpdate === "function") {
|
|
575
|
+
this.onBodyUpdate(this);
|
|
573
576
|
}
|
|
574
|
-
|
|
577
|
+
*/
|
|
578
|
+
}
|
|
575
579
|
return this;
|
|
576
580
|
}
|
|
577
581
|
|