melonjs 14.5.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 +2 -2
- 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 +2 -4
- 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 +4 -4
- 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 +5 -3
- 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 +2 -2
- 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 +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 +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 +9 -8
- package/dist/melonjs.mjs/math/math.js +1 -1
- package/dist/melonjs.mjs/math/matrix2.js +1 -1
- package/dist/melonjs.mjs/math/matrix3.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector2.js +1 -1
- package/dist/melonjs.mjs/math/observable_vector3.js +1 -1
- package/dist/melonjs.mjs/math/vector2.js +1 -1
- package/dist/melonjs.mjs/math/vector3.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/arraymultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/multimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/src/setmultimap.js +1 -1
- package/dist/melonjs.mjs/node_modules/earcut/src/earcut.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index.js +1 -1
- package/dist/melonjs.mjs/node_modules/eventemitter3/index2.js +1 -1
- package/dist/melonjs.mjs/node_modules/howler/dist/howler.js +1 -1
- package/dist/melonjs.mjs/particles/emitter.js +1 -1
- package/dist/melonjs.mjs/particles/particle.js +1 -1
- package/dist/melonjs.mjs/particles/settings.js +1 -1
- package/dist/melonjs.mjs/physics/body.js +1 -1
- package/dist/melonjs.mjs/physics/bounds.js +1 -1
- package/dist/melonjs.mjs/physics/collision.js +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/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 +25 -3
- 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 -3
- package/dist/melonjs.mjs/state/stage.js +1 -1
- package/dist/melonjs.mjs/state/state.js +1 -1
- 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 +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 +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 +1 -1
- package/dist/melonjs.mjs/utils/utils.js +1 -1
- 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 +3 -9
- 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 +1 -1
- package/dist/melonjs.mjs/video/webgl/buffer/vertex.js +21 -17
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +77 -77
- 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/compositors/webgl_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 +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 +25111 -25202
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/ui/uitextbutton.d.ts +0 -1
- 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 +38 -32
- 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/webgl_renderer.d.ts +34 -28
- package/package.json +13 -14
- package/src/audio/audio.js +1 -3
- package/src/geometries/path2d.js +3 -3
- package/src/index.js +6 -2
- package/src/math/color.js +8 -7
- package/src/polyfill/index.js +0 -2
- package/src/renderable/renderable.js +24 -2
- package/src/renderable/ui/uitextbutton.js +0 -2
- package/src/system/device.js +1 -1
- package/src/text/text.js +55 -85
- package/src/text/textstyle.js +3 -5
- package/src/video/canvas/canvas_renderer.js +5 -9
- package/src/video/renderer.js +0 -11
- package/src/video/texture/atlas.js +2 -8
- package/src/video/webgl/buffer/vertex.js +20 -16
- package/src/video/webgl/compositors/compositor.js +76 -77
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +38 -98
- 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/dist/melonjs.mjs/video/webgl/webgl_compositor.js +0 -494
- package/src/polyfill/performance.js +0 -20
- package/src/polyfill/requestAnimationFrame.js +0 -39
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/polyfill/index.js
CHANGED
|
@@ -206,6 +206,13 @@ import Color from "./../math/color.js";
|
|
|
206
206
|
*/
|
|
207
207
|
this.mask = undefined;
|
|
208
208
|
|
|
209
|
+
/**
|
|
210
|
+
* (Experimental) an optional shader, to be used instead of the default built-in one, when drawing this renderable (WebGL only)
|
|
211
|
+
* @type {GLShader}
|
|
212
|
+
* @default undefined
|
|
213
|
+
*/
|
|
214
|
+
this.shader = undefined;
|
|
215
|
+
|
|
209
216
|
/**
|
|
210
217
|
* the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
|
|
211
218
|
* @type {string}
|
|
@@ -620,9 +627,7 @@ import Color from "./../math/color.js";
|
|
|
620
627
|
// manually update the anchor point (required for updateBoundsPos)
|
|
621
628
|
this.anchorPoint.setMuted(x, y);
|
|
622
629
|
// then call updateBounds
|
|
623
|
-
//this.updateBoundsPos(this.pos.x, this.pos.y);
|
|
624
630
|
this.updateBounds();
|
|
625
|
-
//console.log("hello");
|
|
626
631
|
this.isDirty = true;
|
|
627
632
|
}
|
|
628
633
|
|
|
@@ -650,6 +655,11 @@ import Color from "./../math/color.js";
|
|
|
650
655
|
renderer.translate(-this.pos.x, -this.pos.y);
|
|
651
656
|
}
|
|
652
657
|
|
|
658
|
+
// use this renderable shader if defined
|
|
659
|
+
if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
|
|
660
|
+
renderer.customShader = this.shader;
|
|
661
|
+
}
|
|
662
|
+
|
|
653
663
|
if ((this.autoTransform === true) && (!this.currentTransform.isIdentity())) {
|
|
654
664
|
// apply the renderable transformation matrix
|
|
655
665
|
renderer.translate(this.pos.x, this.pos.y);
|
|
@@ -701,6 +711,12 @@ import Color from "./../math/color.js";
|
|
|
701
711
|
renderer.clearMask();
|
|
702
712
|
}
|
|
703
713
|
|
|
714
|
+
// revert to the default shader if defined
|
|
715
|
+
if (typeof this.shader === "object" && typeof renderer.gl !== "undefined") {
|
|
716
|
+
renderer.customShader = undefined;
|
|
717
|
+
//renderer.setCompositor("quad");
|
|
718
|
+
}
|
|
719
|
+
|
|
704
720
|
// restore the context
|
|
705
721
|
renderer.restore();
|
|
706
722
|
|
|
@@ -780,6 +796,12 @@ import Color from "./../math/color.js";
|
|
|
780
796
|
|
|
781
797
|
// call the user defined destroy method
|
|
782
798
|
this.onDestroyEvent.apply(this, arguments);
|
|
799
|
+
|
|
800
|
+
// destroy any shader object if not done by the user through onDestroyEvent()
|
|
801
|
+
if (typeof this.shader === "object") {
|
|
802
|
+
this.shader.destroy();
|
|
803
|
+
this.shader = undefined;
|
|
804
|
+
}
|
|
783
805
|
}
|
|
784
806
|
|
|
785
807
|
/**
|
|
@@ -24,7 +24,6 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
24
24
|
* @param {string} [settings.backgroundColor] - The css value of a background color
|
|
25
25
|
* @param {string} [settings.hoverColor] - The css value of a color to be used if the pointer hovers over the button
|
|
26
26
|
* @param {string} [settings.borderStrokeColor] - The css value of a color to be used to draw the border
|
|
27
|
-
* @param {boolean} [settings.offScreenCanvas] - Weather to use an offScreen canvas or not
|
|
28
27
|
* @param {string} [settings.fillStyle] - The css value of a tint color to be used to tint the text
|
|
29
28
|
* @param {number} [settings.borderWidth] - Width of the button
|
|
30
29
|
* @param {number} [settings.borderHeight] - Height of the button
|
|
@@ -57,7 +56,6 @@ import UIBaseElement from "./uibaseelement.js";
|
|
|
57
56
|
settings.backgroundColor = settings.backgroundColor || "#00aa00";
|
|
58
57
|
settings.hoverColor = settings.hoverColor || "#00ff00";
|
|
59
58
|
settings.borderStrokeColor = settings.borderStrokeColor || "#000000";
|
|
60
|
-
settings.offScreenCanvas = settings.offScreenCanvas || false;
|
|
61
59
|
settings.fillStyle = settings.fillStyle || "#ffffff";
|
|
62
60
|
settings.lineWidth = settings.lineWidth || 1;
|
|
63
61
|
settings.anchorPoint = settings.anchorPoint || new Vector2d(0, 0);
|
package/src/system/device.js
CHANGED
|
@@ -100,7 +100,7 @@ export const pointerEvent = !!globalThis.PointerEvent;
|
|
|
100
100
|
* @readonly
|
|
101
101
|
* @public
|
|
102
102
|
*/
|
|
103
|
-
export const touch = touchEvent || pointerEvent;
|
|
103
|
+
export const touch = touchEvent || (pointerEvent && globalThis.navigator.maxTouchPoints > 0);
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
106
|
* the maximum number of simultaneous touch contact points are supported by the current device.
|
package/src/text/text.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
|
-
import WebGLRenderer from "./../video/webgl/webgl_renderer.js";
|
|
3
2
|
import { renderer as globalRenderer } from "./../video/video.js";
|
|
4
3
|
import pool from "./../system/pooling.js";
|
|
5
4
|
import Renderable from "./../renderable/renderable.js";
|
|
@@ -19,18 +18,6 @@ import TextMetrics from "./textmetrics.js";
|
|
|
19
18
|
const runits = ["ex", "em", "pt", "px"];
|
|
20
19
|
const toPX = [12, 24, 0.75, 1];
|
|
21
20
|
|
|
22
|
-
// return a valid 2d context for Text rendering/styling
|
|
23
|
-
var getContext2d = function (renderer, text) {
|
|
24
|
-
if (text.offScreenCanvas === true) {
|
|
25
|
-
return text.canvasTexture.context;
|
|
26
|
-
} else {
|
|
27
|
-
if (typeof renderer === "undefined") {
|
|
28
|
-
renderer = globalRenderer;
|
|
29
|
-
}
|
|
30
|
-
return renderer.getFontContext();
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
21
|
/**
|
|
35
22
|
* @classdesc
|
|
36
23
|
* a generic system font object.
|
|
@@ -45,12 +32,11 @@ var getContext2d = function (renderer, text) {
|
|
|
45
32
|
* @param {number|string} settings.size - size, or size + suffix (px, em, pt)
|
|
46
33
|
* @param {Color|string} [settings.fillStyle="#000000"] - a CSS color value
|
|
47
34
|
* @param {Color|string} [settings.strokeStyle="#000000"] - a CSS color value
|
|
48
|
-
* @param {number} [settings.lineWidth=
|
|
35
|
+
* @param {number} [settings.lineWidth=0] - line width, in pixels, when drawing stroke
|
|
49
36
|
* @param {string} [settings.textAlign="left"] - horizontal text alignment
|
|
50
37
|
* @param {string} [settings.textBaseline="top"] - the text baseline
|
|
51
38
|
* @param {number} [settings.lineHeight=1.0] - line spacing height
|
|
52
39
|
* @param {Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] - anchor point to draw the text at
|
|
53
|
-
* @param {boolean} [settings.offScreenCanvas=false] - whether to draw the font to an individual "cache" texture first
|
|
54
40
|
* @param {number} [settings.wordWrapWidth] - the maximum length in CSS pixel for a single segment of text
|
|
55
41
|
* @param {(string|string[])} [settings.text=""] - a string, or an array of strings
|
|
56
42
|
* @example
|
|
@@ -105,9 +91,9 @@ var getContext2d = function (renderer, text) {
|
|
|
105
91
|
* sets the current line width, in pixels, when drawing stroke
|
|
106
92
|
* @public
|
|
107
93
|
* @type {number}
|
|
108
|
-
* @default
|
|
94
|
+
* @default 0
|
|
109
95
|
*/
|
|
110
|
-
this.lineWidth = settings.lineWidth ||
|
|
96
|
+
this.lineWidth = settings.lineWidth || 0;
|
|
111
97
|
|
|
112
98
|
/**
|
|
113
99
|
* Set the default text alignment (or justification),<br>
|
|
@@ -136,16 +122,6 @@ var getContext2d = function (renderer, text) {
|
|
|
136
122
|
*/
|
|
137
123
|
this.lineHeight = settings.lineHeight || 1.0;
|
|
138
124
|
|
|
139
|
-
/**
|
|
140
|
-
* whether to draw the font to a indidividual offscreen canvas texture first <br>
|
|
141
|
-
* Note: this will improve performances when using WebGL, but will impact
|
|
142
|
-
* memory consumption as every text element will have its own canvas texture
|
|
143
|
-
* @public
|
|
144
|
-
* @type {boolean}
|
|
145
|
-
* @default false
|
|
146
|
-
*/
|
|
147
|
-
this.offScreenCanvas = false;
|
|
148
|
-
|
|
149
125
|
/**
|
|
150
126
|
* the maximum length in CSS pixel for a single segment of text.
|
|
151
127
|
* (use -1 to disable word wrapping)
|
|
@@ -192,10 +168,8 @@ var getContext2d = function (renderer, text) {
|
|
|
192
168
|
this.italic();
|
|
193
169
|
}
|
|
194
170
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
|
|
198
|
-
}
|
|
171
|
+
// the canvas Texture used to render this text
|
|
172
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: true });
|
|
199
173
|
|
|
200
174
|
// instance to text metrics functions
|
|
201
175
|
this.metrics = new TextMetrics(this);
|
|
@@ -284,38 +258,38 @@ var getContext2d = function (renderer, text) {
|
|
|
284
258
|
|
|
285
259
|
// word wrap if necessary
|
|
286
260
|
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
287
|
-
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth,
|
|
261
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
|
|
288
262
|
}
|
|
289
263
|
|
|
290
264
|
// calculcate the text size and update the bounds accordingly
|
|
291
|
-
bounds.addBounds(this.metrics.measureText(this._text,
|
|
265
|
+
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
292
266
|
|
|
293
267
|
// update the offScreenCanvas texture if required
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// resize the cache canvas if necessary
|
|
311
|
-
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
312
|
-
this.canvasTexture.resize(width, height);
|
|
268
|
+
var width = Math.ceil(this.metrics.width),
|
|
269
|
+
height = Math.ceil(this.metrics.height);
|
|
270
|
+
|
|
271
|
+
if (typeof globalRenderer.gl !== "undefined") {
|
|
272
|
+
// make sure the right compositor is active
|
|
273
|
+
globalRenderer.setCompositor("quad");
|
|
274
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
275
|
+
this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvasTexture.canvas));
|
|
276
|
+
globalRenderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
277
|
+
|
|
278
|
+
if (globalRenderer.WebGLVersion === 1) {
|
|
279
|
+
// round size to next Pow2
|
|
280
|
+
width = nextPowerOfTwo(this.metrics.width);
|
|
281
|
+
height = nextPowerOfTwo(this.metrics.height);
|
|
313
282
|
}
|
|
283
|
+
}
|
|
314
284
|
|
|
315
|
-
|
|
316
|
-
|
|
285
|
+
// resize the cache canvas if necessary
|
|
286
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
287
|
+
this.canvasTexture.resize(width, height);
|
|
317
288
|
}
|
|
318
289
|
|
|
290
|
+
this.canvasTexture.clear();
|
|
291
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
|
|
292
|
+
|
|
319
293
|
this.isDirty = true;
|
|
320
294
|
|
|
321
295
|
return this;
|
|
@@ -328,7 +302,7 @@ var getContext2d = function (renderer, text) {
|
|
|
328
302
|
* @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
|
|
329
303
|
*/
|
|
330
304
|
measureText(renderer, text = this._text) {
|
|
331
|
-
return this.metrics.measureText(text,
|
|
305
|
+
return this.metrics.measureText(text, this.canvasTexture.context);
|
|
332
306
|
}
|
|
333
307
|
|
|
334
308
|
|
|
@@ -338,9 +312,8 @@ var getContext2d = function (renderer, text) {
|
|
|
338
312
|
* @param {string} [text]
|
|
339
313
|
* @param {number} [x]
|
|
340
314
|
* @param {number} [y]
|
|
341
|
-
* @param {boolean} [stroke=false] - draw stroke the the text if true
|
|
342
315
|
*/
|
|
343
|
-
draw(renderer, text, x = this.pos.x, y = this.pos.y
|
|
316
|
+
draw(renderer, text, x = this.pos.x, y = this.pos.y) {
|
|
344
317
|
// "hacky patch" for backward compatibilty
|
|
345
318
|
if (typeof this.ancestor === "undefined") {
|
|
346
319
|
|
|
@@ -354,21 +327,18 @@ var getContext2d = function (renderer, text) {
|
|
|
354
327
|
// update text cache
|
|
355
328
|
this.setText(text);
|
|
356
329
|
|
|
357
|
-
x = this.metrics.x;
|
|
358
|
-
y = this.metrics.y;
|
|
359
|
-
|
|
360
330
|
// save the previous context
|
|
361
331
|
renderer.save();
|
|
362
332
|
|
|
363
333
|
// apply the defined alpha value
|
|
364
334
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
365
335
|
|
|
366
|
-
} else {
|
|
367
|
-
// added directly to an object container
|
|
368
|
-
x = this.pos.x;
|
|
369
|
-
y = this.pos.y;
|
|
370
336
|
}
|
|
371
337
|
|
|
338
|
+
// adjust x,y position based on the bounding box
|
|
339
|
+
x = this.metrics.x;
|
|
340
|
+
y = this.metrics.y;
|
|
341
|
+
|
|
372
342
|
// clamp to pixel grid if required
|
|
373
343
|
if (renderer.settings.subPixel === false) {
|
|
374
344
|
x = ~~x;
|
|
@@ -376,12 +346,7 @@ var getContext2d = function (renderer, text) {
|
|
|
376
346
|
}
|
|
377
347
|
|
|
378
348
|
// draw the text
|
|
379
|
-
|
|
380
|
-
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
381
|
-
} else {
|
|
382
|
-
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
|
|
383
|
-
}
|
|
384
|
-
|
|
349
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
385
350
|
|
|
386
351
|
// for backward compatibilty
|
|
387
352
|
if (typeof this.ancestor === "undefined") {
|
|
@@ -391,28 +356,33 @@ var getContext2d = function (renderer, text) {
|
|
|
391
356
|
}
|
|
392
357
|
|
|
393
358
|
/**
|
|
394
|
-
* draw a stroke text at the specified coord, as defined
|
|
395
|
-
*
|
|
396
|
-
* Note : using drawStroke is not recommended for performance reasons
|
|
359
|
+
* draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
|
|
360
|
+
* @deprecated since 15.0.0
|
|
397
361
|
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
398
362
|
* @param {string} text
|
|
399
363
|
* @param {number} x
|
|
400
364
|
* @param {number} y
|
|
401
365
|
*/
|
|
402
366
|
drawStroke(renderer, text, x, y) {
|
|
403
|
-
this.draw(renderer, text, x, y
|
|
367
|
+
this.draw(renderer, text, x, y);
|
|
404
368
|
}
|
|
405
369
|
|
|
406
370
|
/**
|
|
407
371
|
* @ignore
|
|
408
372
|
*/
|
|
409
|
-
_drawFont(context, text, x, y
|
|
410
|
-
setContextStyle(context, this
|
|
373
|
+
_drawFont(context, text, x, y) {
|
|
374
|
+
setContextStyle(context, this);
|
|
411
375
|
|
|
412
376
|
for (var i = 0; i < text.length; i++) {
|
|
413
377
|
var string = text[i].trimEnd();
|
|
414
378
|
// draw the string
|
|
415
|
-
|
|
379
|
+
if (this.fillStyle.alpha > 0) {
|
|
380
|
+
context.fillText(string, x, y);
|
|
381
|
+
}
|
|
382
|
+
// stroke the text
|
|
383
|
+
if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
|
|
384
|
+
context.strokeText(string, x, y);
|
|
385
|
+
}
|
|
416
386
|
// add leading space
|
|
417
387
|
y += this.metrics.lineHeight();
|
|
418
388
|
}
|
|
@@ -424,15 +394,15 @@ var getContext2d = function (renderer, text) {
|
|
|
424
394
|
* @ignore
|
|
425
395
|
*/
|
|
426
396
|
destroy() {
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
433
|
-
pool.push(this.canvasTexture);
|
|
434
|
-
this.canvasTexture = undefined;
|
|
397
|
+
if (typeof globalRenderer.gl !== "undefined") {
|
|
398
|
+
// make sure the right compositor is active
|
|
399
|
+
globalRenderer.setCompositor("quad");
|
|
400
|
+
globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
401
|
+
this.glTextureUnit = undefined;
|
|
435
402
|
}
|
|
403
|
+
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
404
|
+
pool.push(this.canvasTexture);
|
|
405
|
+
this.canvasTexture = undefined;
|
|
436
406
|
pool.push(this.fillStyle);
|
|
437
407
|
pool.push(this.strokeStyle);
|
|
438
408
|
this.fillStyle = this.strokeStyle = undefined;
|
package/src/text/textstyle.js
CHANGED
|
@@ -2,13 +2,11 @@
|
|
|
2
2
|
* apply the current text style to the given context
|
|
3
3
|
* @ignore
|
|
4
4
|
*/
|
|
5
|
-
export default function setContextStyle(context, style
|
|
5
|
+
export default function setContextStyle(context, style) {
|
|
6
6
|
context.font = style.font;
|
|
7
7
|
context.fillStyle = style.fillStyle.toRGBA();
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
context.lineWidth = style.lineWidth;
|
|
11
|
-
}
|
|
8
|
+
context.strokeStyle = style.strokeStyle.toRGBA();
|
|
9
|
+
context.lineWidth = style.lineWidth;
|
|
12
10
|
context.textAlign = style.textAlign;
|
|
13
11
|
context.textBaseline = style.textBaseline;
|
|
14
12
|
}
|
|
@@ -59,6 +59,11 @@ import * as event from "./../../system/event.js";
|
|
|
59
59
|
this.isContextValid = true;
|
|
60
60
|
event.emit(event.ONCONTEXT_RESTORED, this);
|
|
61
61
|
}, false );
|
|
62
|
+
|
|
63
|
+
// reset the renderer on game reset
|
|
64
|
+
event.on(event.GAME_RESET, () => {
|
|
65
|
+
this.reset();
|
|
66
|
+
});
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
@@ -534,15 +539,6 @@ import * as event from "./../../system/event.js";
|
|
|
534
539
|
this.strokePoint(x, y);
|
|
535
540
|
}
|
|
536
541
|
|
|
537
|
-
/**
|
|
538
|
-
* return a reference to the font 2d Context
|
|
539
|
-
* @ignore
|
|
540
|
-
*/
|
|
541
|
-
getFontContext() {
|
|
542
|
-
// in canvas mode we can directly use the 2d context
|
|
543
|
-
return this.getContext();
|
|
544
|
-
}
|
|
545
|
-
|
|
546
542
|
/**
|
|
547
543
|
* save the canvas context
|
|
548
544
|
* @name save
|
package/src/video/renderer.js
CHANGED
|
@@ -115,11 +115,6 @@ import Point from "../geometries/point.js";
|
|
|
115
115
|
|
|
116
116
|
// default uvOffset
|
|
117
117
|
this.uvOffset = 0;
|
|
118
|
-
|
|
119
|
-
// reset the renderer on game reset
|
|
120
|
-
event.on(event.GAME_RESET, () => {
|
|
121
|
-
this.reset();
|
|
122
|
-
});
|
|
123
118
|
}
|
|
124
119
|
|
|
125
120
|
/**
|
|
@@ -412,10 +407,4 @@ import Point from "../geometries/point.js";
|
|
|
412
407
|
// reset to default
|
|
413
408
|
this.currentTint.setColor(255, 255, 255, 1.0);
|
|
414
409
|
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* @ignore
|
|
418
|
-
*/
|
|
419
|
-
drawFont(/*bounds*/) {}
|
|
420
|
-
|
|
421
410
|
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import Vector2d from "./../../math/vector2.js";
|
|
2
|
-
import WebGLRenderer from "./../webgl/webgl_renderer.js";
|
|
3
|
-
import TextureCache from "./../texture/cache.js";
|
|
4
2
|
import Sprite from "./../../renderable/sprite.js";
|
|
5
3
|
import { renderer } from "./../video.js";
|
|
6
4
|
import pool from "./../../system/pooling.js";
|
|
@@ -159,11 +157,7 @@ export class TextureAtlas {
|
|
|
159
157
|
// Add self to TextureCache if cache !== false
|
|
160
158
|
if (cache !== false) {
|
|
161
159
|
this.sources.forEach((source) => {
|
|
162
|
-
|
|
163
|
-
cache.set(source, this);
|
|
164
|
-
} else {
|
|
165
|
-
renderer.cache.set(source, this);
|
|
166
|
-
}
|
|
160
|
+
renderer.cache.set(source, this);
|
|
167
161
|
});
|
|
168
162
|
}
|
|
169
163
|
}
|
|
@@ -388,7 +382,7 @@ export class TextureAtlas {
|
|
|
388
382
|
*/
|
|
389
383
|
addUVs(atlas, name, w, h) {
|
|
390
384
|
// ignore if using the Canvas Renderer
|
|
391
|
-
if (renderer
|
|
385
|
+
if (typeof renderer.gl !== "undefined") {
|
|
392
386
|
// Source coordinates
|
|
393
387
|
var s = atlas[name].offset;
|
|
394
388
|
var sw = atlas[name].width;
|
|
@@ -7,18 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
export default class VertexArrayBuffer {
|
|
9
9
|
|
|
10
|
-
constructor(vertex_size,
|
|
10
|
+
constructor(vertex_size, vertex_per_obj) {
|
|
11
11
|
// the size of one vertex in float
|
|
12
12
|
this.vertexSize = vertex_size;
|
|
13
|
-
// size of
|
|
14
|
-
this.
|
|
13
|
+
// size of an object in vertex
|
|
14
|
+
this.objSize = vertex_per_obj;
|
|
15
15
|
// the maximum number of vertices the vertex array buffer can hold
|
|
16
|
-
this.maxVertex = 256;
|
|
16
|
+
this.maxVertex = 256; // (note: this seems to be the sweet spot performance-wise when using batching)
|
|
17
17
|
// the current number of vertices added to the vertex array buffer
|
|
18
18
|
this.vertexCount = 0;
|
|
19
19
|
|
|
20
20
|
// the actual vertex data buffer
|
|
21
|
-
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.
|
|
21
|
+
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
|
|
22
22
|
// Float32 and Uint32 view of the vertex data array buffer
|
|
23
23
|
this.bufferF32 = new Float32Array(this.buffer);
|
|
24
24
|
this.bufferU32 = new Uint32Array(this.buffer);
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* return true if full
|
|
38
38
|
* @ignore
|
|
39
39
|
*/
|
|
40
|
-
isFull(vertex = this.
|
|
40
|
+
isFull(vertex = this.objSize) {
|
|
41
41
|
return (this.vertexCount + vertex >= this.maxVertex);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -45,14 +45,18 @@
|
|
|
45
45
|
* resize the vertex buffer, retaining its original contents
|
|
46
46
|
* @ignore
|
|
47
47
|
*/
|
|
48
|
-
resize() {
|
|
49
|
-
|
|
50
|
-
this.maxVertex
|
|
48
|
+
resize(vertexCount) {
|
|
49
|
+
|
|
50
|
+
while (vertexCount > this.maxVertex) {
|
|
51
|
+
// double the vertex size
|
|
52
|
+
this.maxVertex <<= 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
// save a reference to the previous data
|
|
52
56
|
var data = this.bufferF32;
|
|
53
57
|
|
|
54
58
|
// recreate ArrayBuffer and views
|
|
55
|
-
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.
|
|
59
|
+
this.buffer = new ArrayBuffer(this.maxVertex * this.vertexSize * this.objSize);
|
|
56
60
|
this.bufferF32 = new Float32Array(this.buffer);
|
|
57
61
|
this.bufferU32 = new Uint32Array(this.buffer);
|
|
58
62
|
|
|
@@ -70,19 +74,19 @@
|
|
|
70
74
|
var offset = this.vertexCount * this.vertexSize;
|
|
71
75
|
|
|
72
76
|
if (this.vertexCount >= this.maxVertex) {
|
|
73
|
-
this.resize();
|
|
77
|
+
this.resize(this.vertexCount);
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
this.bufferF32[offset
|
|
77
|
-
this.bufferF32[offset
|
|
80
|
+
this.bufferF32[offset] = x;
|
|
81
|
+
this.bufferF32[++offset] = y;
|
|
78
82
|
|
|
79
83
|
if (typeof u !== "undefined") {
|
|
80
|
-
this.bufferF32[offset
|
|
81
|
-
this.bufferF32[offset
|
|
84
|
+
this.bufferF32[++offset] = u;
|
|
85
|
+
this.bufferF32[++offset] = v;
|
|
82
86
|
}
|
|
83
87
|
|
|
84
88
|
if (typeof tint !== "undefined") {
|
|
85
|
-
this.bufferU32[offset
|
|
89
|
+
this.bufferU32[++offset] = tint;
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
this.vertexCount++;
|