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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -107,7 +107,7 @@ const pointerEvent = !!globalThis.PointerEvent;
|
|
|
107
107
|
* @readonly
|
|
108
108
|
* @public
|
|
109
109
|
*/
|
|
110
|
-
const touch = touchEvent || pointerEvent;
|
|
110
|
+
const touch = touchEvent || (pointerEvent && globalThis.navigator.maxTouchPoints > 0);
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* the maximum number of simultaneous touch contact points are supported by the current device.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -35,14 +35,14 @@ class ObjectPool {
|
|
|
35
35
|
* @param {boolean} [recycling=false] - enables object recycling for the specified class
|
|
36
36
|
* @example
|
|
37
37
|
* // implement CherryEntity
|
|
38
|
-
* class
|
|
38
|
+
* class Cherry extends Sprite {
|
|
39
39
|
* onResetEvent() {
|
|
40
40
|
* // reset object mutable properties
|
|
41
41
|
* this.lifeBar = 100;
|
|
42
42
|
* }
|
|
43
43
|
* };
|
|
44
44
|
* // add our users defined entities in the object pool and enable object recycling
|
|
45
|
-
* me.pool.register("
|
|
45
|
+
* me.pool.register("cherrysprite", Cherry, true);
|
|
46
46
|
*/
|
|
47
47
|
register(className, classObj, recycling = false) {
|
|
48
48
|
if (typeof (classObj) !== "undefined") {
|
|
@@ -76,11 +76,7 @@ class ObjectPool {
|
|
|
76
76
|
* me.game.world.removeChild(enemy);
|
|
77
77
|
* me.game.world.removeChild(bullet);
|
|
78
78
|
*/
|
|
79
|
-
pull(name) {
|
|
80
|
-
var args = new Array(arguments.length);
|
|
81
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
82
|
-
args[i] = arguments[i];
|
|
83
|
-
}
|
|
79
|
+
pull(name, ...args) {
|
|
84
80
|
var className = this.objectClass[name];
|
|
85
81
|
if (className) {
|
|
86
82
|
var proto = className["class"],
|
|
@@ -88,18 +84,12 @@ class ObjectPool {
|
|
|
88
84
|
obj;
|
|
89
85
|
|
|
90
86
|
if (poolArray && ((obj = poolArray.pop()))) {
|
|
91
|
-
//
|
|
92
|
-
|
|
93
|
-
// call the object onResetEvent function if defined
|
|
94
|
-
if (typeof(obj.onResetEvent) === "function") {
|
|
95
|
-
obj.onResetEvent.apply(obj, args);
|
|
96
|
-
}
|
|
87
|
+
// poolable object must implement a `onResetEvent` method
|
|
88
|
+
obj.onResetEvent.apply(obj, args);
|
|
97
89
|
this.instance_counter--;
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
90
|
+
} else {
|
|
100
91
|
// create a new instance
|
|
101
|
-
|
|
102
|
-
obj = new (proto.bind.apply(proto, args))();
|
|
92
|
+
obj = new (proto.bind.apply(proto, [ proto, ...args ]))();
|
|
103
93
|
if (poolArray) {
|
|
104
94
|
obj.className = name;
|
|
105
95
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import Color from '../math/color.js';
|
|
9
9
|
import pool from '../system/pooling.js';
|
|
10
|
-
import
|
|
10
|
+
import { getImage, getBinary } from '../loader/loader.js';
|
|
11
11
|
import Renderable from '../renderable/renderable.js';
|
|
12
12
|
import TextMetrics from './textmetrics.js';
|
|
13
13
|
|
|
@@ -102,7 +102,7 @@ import TextMetrics from './textmetrics.js';
|
|
|
102
102
|
* font image
|
|
103
103
|
* @private
|
|
104
104
|
*/
|
|
105
|
-
this.fontImage = (typeof settings.font === "object") ? settings.font :
|
|
105
|
+
this.fontImage = (typeof settings.font === "object") ? settings.font : getImage(settings.font);
|
|
106
106
|
|
|
107
107
|
if (typeof settings.fontData !== "string") {
|
|
108
108
|
/**
|
|
@@ -110,11 +110,11 @@ import TextMetrics from './textmetrics.js';
|
|
|
110
110
|
* @private
|
|
111
111
|
*/
|
|
112
112
|
// use settings.font to retreive the data from the loader
|
|
113
|
-
this.fontData = pool.pull("BitmapTextData",
|
|
113
|
+
this.fontData = pool.pull("BitmapTextData", getBinary(settings.font));
|
|
114
114
|
} else {
|
|
115
115
|
this.fontData = pool.pull("BitmapTextData",
|
|
116
116
|
// if starting/includes "info face" the whole data string was passed as parameter
|
|
117
|
-
(settings.fontData.includes("info face")) ? settings.fontData :
|
|
117
|
+
(settings.fontData.includes("info face")) ? settings.fontData : getBinary(settings.fontData)
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -183,11 +183,70 @@ import TextMetrics from './textmetrics.js';
|
|
|
183
183
|
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth);
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
this.
|
|
186
|
+
this.updateBounds();
|
|
187
187
|
|
|
188
188
|
return this;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
/**
|
|
192
|
+
* update the bounding box for this Bitmap Text.
|
|
193
|
+
* @param {boolean} [absolute=true] - update the bounds size and position in (world) absolute coordinates
|
|
194
|
+
* @returns {Bounds} this Bitmap Text bounding box Rectangle object
|
|
195
|
+
*/
|
|
196
|
+
updateBounds(absolute = true) {
|
|
197
|
+
var bounds = this.getBounds();
|
|
198
|
+
|
|
199
|
+
bounds.clear();
|
|
200
|
+
|
|
201
|
+
if (typeof this.metrics !== "undefined") {
|
|
202
|
+
var ax, ay;
|
|
203
|
+
|
|
204
|
+
bounds.addBounds(this.metrics.measureText(this._text));
|
|
205
|
+
|
|
206
|
+
switch (this.textAlign) {
|
|
207
|
+
case "right":
|
|
208
|
+
ax = this.metrics.width * 1.0;
|
|
209
|
+
break;
|
|
210
|
+
|
|
211
|
+
case "center":
|
|
212
|
+
ax = this.metrics.width * 0.5;
|
|
213
|
+
break;
|
|
214
|
+
|
|
215
|
+
default :
|
|
216
|
+
ax = this.metrics.width * 0.0;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// adjust y pos based on alignment value
|
|
221
|
+
switch (this.textBaseline) {
|
|
222
|
+
case "middle":
|
|
223
|
+
ay = this.metrics.height * 0.5;
|
|
224
|
+
break;
|
|
225
|
+
|
|
226
|
+
case "ideographic":
|
|
227
|
+
case "alphabetic":
|
|
228
|
+
case "bottom":
|
|
229
|
+
ay = this.metrics.height * 1.0;
|
|
230
|
+
break;
|
|
231
|
+
|
|
232
|
+
default :
|
|
233
|
+
ay = this.metrics.height * 0.0;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// translate the bounds accordingly
|
|
238
|
+
bounds.translate(ax, ay);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (absolute === true) {
|
|
242
|
+
if (typeof this.ancestor !== "undefined" && typeof this.ancestor.addChild === "function" && this.floating !== true) {
|
|
243
|
+
bounds.translate(this.ancestor.getAbsolutePosition());
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return bounds;
|
|
248
|
+
}
|
|
249
|
+
|
|
191
250
|
/**
|
|
192
251
|
* defines the color used to tint the bitmap text
|
|
193
252
|
* @public
|
|
@@ -214,9 +273,8 @@ import TextMetrics from './textmetrics.js';
|
|
|
214
273
|
resize(scale) {
|
|
215
274
|
this.fontScale.set(scale, scale);
|
|
216
275
|
|
|
217
|
-
this.
|
|
276
|
+
this.updateBounds();
|
|
218
277
|
|
|
219
|
-
// clear the cache text to recalculate bounds
|
|
220
278
|
this.isDirty = true;
|
|
221
279
|
|
|
222
280
|
return this;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
6
6
|
* @copyright (C) 2011 - 2023 Olivier Biot (AltByte Pte Ltd)
|
|
7
7
|
*/
|
|
8
8
|
import Color from '../math/color.js';
|
|
9
|
-
import WebGLRenderer from '../video/webgl/webgl_renderer.js';
|
|
10
9
|
import { renderer } from '../video/video.js';
|
|
11
10
|
import pool from '../system/pooling.js';
|
|
12
11
|
import Renderable from '../renderable/renderable.js';
|
|
@@ -26,18 +25,6 @@ import TextMetrics from './textmetrics.js';
|
|
|
26
25
|
const runits = ["ex", "em", "pt", "px"];
|
|
27
26
|
const toPX = [12, 24, 0.75, 1];
|
|
28
27
|
|
|
29
|
-
// return a valid 2d context for Text rendering/styling
|
|
30
|
-
var getContext2d = function (renderer$1, text) {
|
|
31
|
-
if (text.offScreenCanvas === true) {
|
|
32
|
-
return text.canvasTexture.context;
|
|
33
|
-
} else {
|
|
34
|
-
if (typeof renderer$1 === "undefined") {
|
|
35
|
-
renderer$1 = renderer;
|
|
36
|
-
}
|
|
37
|
-
return renderer$1.getFontContext();
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
28
|
/**
|
|
42
29
|
* @classdesc
|
|
43
30
|
* a generic system font object.
|
|
@@ -52,12 +39,11 @@ var getContext2d = function (renderer$1, text) {
|
|
|
52
39
|
* @param {number|string} settings.size - size, or size + suffix (px, em, pt)
|
|
53
40
|
* @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
|
|
54
41
|
* @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
|
|
55
|
-
* @param {number} [settings.lineWidth=
|
|
42
|
+
* @param {number} [settings.lineWidth=0] - line width, in pixels, when drawing stroke
|
|
56
43
|
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
57
44
|
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
58
45
|
* @param {number} [settings.lineHeight=1.0] - line spacing height
|
|
59
46
|
* @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
|
|
60
|
-
* @param {boolean} [settings.offScreenCanvas=false] - whether to draw the font to an individual "cache" texture first
|
|
61
47
|
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
62
48
|
* @param {(string|string[])} [settings.text=""] - a string, or an array of strings
|
|
63
49
|
* @example
|
|
@@ -112,9 +98,9 @@ var getContext2d = function (renderer$1, text) {
|
|
|
112
98
|
* sets the current line width, in pixels, when drawing stroke
|
|
113
99
|
* @public
|
|
114
100
|
* @type {number}
|
|
115
|
-
* @default
|
|
101
|
+
* @default 0
|
|
116
102
|
*/
|
|
117
|
-
this.lineWidth = settings.lineWidth ||
|
|
103
|
+
this.lineWidth = settings.lineWidth || 0;
|
|
118
104
|
|
|
119
105
|
/**
|
|
120
106
|
* Set the default text alignment (or justification),<br>
|
|
@@ -143,16 +129,6 @@ var getContext2d = function (renderer$1, text) {
|
|
|
143
129
|
*/
|
|
144
130
|
this.lineHeight = settings.lineHeight || 1.0;
|
|
145
131
|
|
|
146
|
-
/**
|
|
147
|
-
* whether to draw the font to a indidividual offscreen canvas texture first <br>
|
|
148
|
-
* Note: this will improve performances when using WebGL, but will impact
|
|
149
|
-
* memory consumption as every text element will have its own canvas texture
|
|
150
|
-
* @public
|
|
151
|
-
* @type {boolean}
|
|
152
|
-
* @default false
|
|
153
|
-
*/
|
|
154
|
-
this.offScreenCanvas = false;
|
|
155
|
-
|
|
156
132
|
/**
|
|
157
133
|
* the maximum length in CSS pixel for a single segment of text.
|
|
158
134
|
* (use -1 to disable word wrapping)
|
|
@@ -199,10 +175,8 @@ var getContext2d = function (renderer$1, text) {
|
|
|
199
175
|
this.italic();
|
|
200
176
|
}
|
|
201
177
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
|
|
205
|
-
}
|
|
178
|
+
// the canvas Texture used to render this text
|
|
179
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
|
|
206
180
|
|
|
207
181
|
// instance to text metrics functions
|
|
208
182
|
this.metrics = new TextMetrics(this);
|
|
@@ -291,38 +265,38 @@ var getContext2d = function (renderer$1, text) {
|
|
|
291
265
|
|
|
292
266
|
// word wrap if necessary
|
|
293
267
|
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
294
|
-
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth,
|
|
268
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
|
|
295
269
|
}
|
|
296
270
|
|
|
297
271
|
// calculcate the text size and update the bounds accordingly
|
|
298
|
-
bounds.addBounds(this.metrics.measureText(this._text,
|
|
272
|
+
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
299
273
|
|
|
300
274
|
// update the offScreenCanvas texture if required
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// resize the cache canvas if necessary
|
|
318
|
-
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
319
|
-
this.canvasTexture.resize(width, height);
|
|
275
|
+
var width = Math.ceil(this.metrics.width),
|
|
276
|
+
height = Math.ceil(this.metrics.height);
|
|
277
|
+
|
|
278
|
+
if (typeof renderer.gl !== "undefined") {
|
|
279
|
+
// make sure the right compositor is active
|
|
280
|
+
renderer.setCompositor("quad");
|
|
281
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
282
|
+
this.glTextureUnit = renderer.cache.getUnit(renderer.cache.get(this.canvasTexture.canvas));
|
|
283
|
+
renderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
284
|
+
|
|
285
|
+
if (renderer.WebGLVersion === 1) {
|
|
286
|
+
// round size to next Pow2
|
|
287
|
+
width = nextPowerOfTwo(this.metrics.width);
|
|
288
|
+
height = nextPowerOfTwo(this.metrics.height);
|
|
320
289
|
}
|
|
290
|
+
}
|
|
321
291
|
|
|
322
|
-
|
|
323
|
-
|
|
292
|
+
// resize the cache canvas if necessary
|
|
293
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
294
|
+
this.canvasTexture.resize(width, height);
|
|
324
295
|
}
|
|
325
296
|
|
|
297
|
+
this.canvasTexture.clear();
|
|
298
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
|
|
299
|
+
|
|
326
300
|
this.isDirty = true;
|
|
327
301
|
|
|
328
302
|
return this;
|
|
@@ -335,7 +309,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
335
309
|
* @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
|
|
336
310
|
*/
|
|
337
311
|
measureText(renderer, text = this._text) {
|
|
338
|
-
return this.metrics.measureText(text,
|
|
312
|
+
return this.metrics.measureText(text, this.canvasTexture.context);
|
|
339
313
|
}
|
|
340
314
|
|
|
341
315
|
|
|
@@ -345,9 +319,8 @@ var getContext2d = function (renderer$1, text) {
|
|
|
345
319
|
* @param {string} [text]
|
|
346
320
|
* @param {number} [x]
|
|
347
321
|
* @param {number} [y]
|
|
348
|
-
* @param {boolean} [stroke=false] - draw stroke the the text if true
|
|
349
322
|
*/
|
|
350
|
-
draw(renderer, text, x = this.pos.x, y = this.pos.y
|
|
323
|
+
draw(renderer, text, x = this.pos.x, y = this.pos.y) {
|
|
351
324
|
// "hacky patch" for backward compatibilty
|
|
352
325
|
if (typeof this.ancestor === "undefined") {
|
|
353
326
|
|
|
@@ -361,21 +334,18 @@ var getContext2d = function (renderer$1, text) {
|
|
|
361
334
|
// update text cache
|
|
362
335
|
this.setText(text);
|
|
363
336
|
|
|
364
|
-
x = this.metrics.x;
|
|
365
|
-
y = this.metrics.y;
|
|
366
|
-
|
|
367
337
|
// save the previous context
|
|
368
338
|
renderer.save();
|
|
369
339
|
|
|
370
340
|
// apply the defined alpha value
|
|
371
341
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
372
342
|
|
|
373
|
-
} else {
|
|
374
|
-
// added directly to an object container
|
|
375
|
-
x = this.pos.x;
|
|
376
|
-
y = this.pos.y;
|
|
377
343
|
}
|
|
378
344
|
|
|
345
|
+
// adjust x,y position based on the bounding box
|
|
346
|
+
x = this.metrics.x;
|
|
347
|
+
y = this.metrics.y;
|
|
348
|
+
|
|
379
349
|
// clamp to pixel grid if required
|
|
380
350
|
if (renderer.settings.subPixel === false) {
|
|
381
351
|
x = ~~x;
|
|
@@ -383,12 +353,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
383
353
|
}
|
|
384
354
|
|
|
385
355
|
// draw the text
|
|
386
|
-
|
|
387
|
-
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
388
|
-
} else {
|
|
389
|
-
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
|
|
390
|
-
}
|
|
391
|
-
|
|
356
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
392
357
|
|
|
393
358
|
// for backward compatibilty
|
|
394
359
|
if (typeof this.ancestor === "undefined") {
|
|
@@ -398,28 +363,33 @@ var getContext2d = function (renderer$1, text) {
|
|
|
398
363
|
}
|
|
399
364
|
|
|
400
365
|
/**
|
|
401
|
-
* draw a stroke text at the specified coord, as defined
|
|
402
|
-
*
|
|
403
|
-
* Note : using drawStroke is not recommended for performance reasons
|
|
366
|
+
* draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
|
|
367
|
+
* @deprecated since 15.0.0
|
|
404
368
|
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
405
369
|
* @param {string} text
|
|
406
370
|
* @param {number} x
|
|
407
371
|
* @param {number} y
|
|
408
372
|
*/
|
|
409
373
|
drawStroke(renderer, text, x, y) {
|
|
410
|
-
this.draw(renderer, text, x, y
|
|
374
|
+
this.draw(renderer, text, x, y);
|
|
411
375
|
}
|
|
412
376
|
|
|
413
377
|
/**
|
|
414
378
|
* @ignore
|
|
415
379
|
*/
|
|
416
|
-
_drawFont(context, text, x, y
|
|
417
|
-
setContextStyle(context, this
|
|
380
|
+
_drawFont(context, text, x, y) {
|
|
381
|
+
setContextStyle(context, this);
|
|
418
382
|
|
|
419
383
|
for (var i = 0; i < text.length; i++) {
|
|
420
384
|
var string = text[i].trimEnd();
|
|
421
385
|
// draw the string
|
|
422
|
-
|
|
386
|
+
if (this.fillStyle.alpha > 0) {
|
|
387
|
+
context.fillText(string, x, y);
|
|
388
|
+
}
|
|
389
|
+
// stroke the text
|
|
390
|
+
if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
|
|
391
|
+
context.strokeText(string, x, y);
|
|
392
|
+
}
|
|
423
393
|
// add leading space
|
|
424
394
|
y += this.metrics.lineHeight();
|
|
425
395
|
}
|
|
@@ -431,15 +401,15 @@ var getContext2d = function (renderer$1, text) {
|
|
|
431
401
|
* @ignore
|
|
432
402
|
*/
|
|
433
403
|
destroy() {
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
renderer.cache.delete(this.canvasTexture.canvas);
|
|
440
|
-
pool.push(this.canvasTexture);
|
|
441
|
-
this.canvasTexture = undefined;
|
|
404
|
+
if (typeof renderer.gl !== "undefined") {
|
|
405
|
+
// make sure the right compositor is active
|
|
406
|
+
renderer.setCompositor("quad");
|
|
407
|
+
renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
408
|
+
this.glTextureUnit = undefined;
|
|
442
409
|
}
|
|
410
|
+
renderer.cache.delete(this.canvasTexture.canvas);
|
|
411
|
+
pool.push(this.canvasTexture);
|
|
412
|
+
this.canvasTexture = undefined;
|
|
443
413
|
pool.push(this.fillStyle);
|
|
444
414
|
pool.push(this.strokeStyle);
|
|
445
415
|
this.fillStyle = this.strokeStyle = undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -9,13 +9,11 @@
|
|
|
9
9
|
* apply the current text style to the given context
|
|
10
10
|
* @ignore
|
|
11
11
|
*/
|
|
12
|
-
function setContextStyle(context, style
|
|
12
|
+
function setContextStyle(context, style) {
|
|
13
13
|
context.font = style.font;
|
|
14
14
|
context.fillStyle = style.fillStyle.toRGBA();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
context.lineWidth = style.lineWidth;
|
|
18
|
-
}
|
|
15
|
+
context.strokeStyle = style.strokeStyle.toRGBA();
|
|
16
|
+
context.lineWidth = style.lineWidth;
|
|
19
17
|
context.textAlign = style.textAlign;
|
|
20
18
|
context.textBaseline = style.textBaseline;
|
|
21
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -34,7 +34,7 @@ function isNumeric(str) {
|
|
|
34
34
|
if (typeof str === "string") {
|
|
35
35
|
str = str.trim();
|
|
36
36
|
}
|
|
37
|
-
return !isNaN(str) &&
|
|
37
|
+
return !isNaN(str) && /^[+-]?(\d+(\.\d+)?|\.\d+)$/.test(str);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.0.0
|
|
3
3
|
* http://www.melonjs.org
|
|
4
4
|
* melonjs is licensed under the MIT License.
|
|
5
5
|
* http://www.opensource.org/licenses/mit-license
|
|
@@ -107,9 +107,7 @@ var utils = {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
// parse the url
|
|
110
|
-
url.slice(1).split("&").filter((value) => {
|
|
111
|
-
return (value !== "");
|
|
112
|
-
}).forEach((value) => {
|
|
110
|
+
url.slice(1).split("&").filter((value) => value !== "").forEach((value) => {
|
|
113
111
|
var kv = value.split("=");
|
|
114
112
|
var k = kv.shift();
|
|
115
113
|
var v = kv.join("=");
|