melonjs 14.5.0 → 15.1.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 +6 -6
- 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 +7 -3
- 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 +27 -17
- package/dist/melonjs.mjs/application/header.js +6 -5
- package/dist/melonjs.mjs/application/resize.js +20 -20
- package/dist/melonjs.mjs/application/settings.js +1 -1
- package/dist/melonjs.mjs/audio/audio.js +18 -20
- package/dist/melonjs.mjs/camera/camera2d.js +10 -10
- package/dist/melonjs.mjs/const.js +1 -1
- package/dist/melonjs.mjs/entity/entity.js +4 -4
- package/dist/melonjs.mjs/geometries/ellipse.js +6 -6
- package/dist/melonjs.mjs/geometries/line.js +9 -9
- package/dist/melonjs.mjs/geometries/path2d.js +56 -56
- package/dist/melonjs.mjs/geometries/point.js +2 -2
- package/dist/melonjs.mjs/geometries/poly.js +29 -29
- package/dist/melonjs.mjs/geometries/rectangle.js +8 -8
- package/dist/melonjs.mjs/geometries/roundrect.js +6 -6
- package/dist/melonjs.mjs/index.js +8 -6
- package/dist/melonjs.mjs/input/gamepad.js +30 -30
- package/dist/melonjs.mjs/input/input.js +2 -2
- package/dist/melonjs.mjs/input/keyboard.js +15 -15
- package/dist/melonjs.mjs/input/pointer.js +2 -2
- package/dist/melonjs.mjs/input/pointerevent.js +59 -59
- package/dist/melonjs.mjs/lang/console.js +3 -3
- package/dist/melonjs.mjs/lang/deprecated.js +2 -2
- package/dist/melonjs.mjs/level/level.js +9 -9
- package/dist/melonjs.mjs/level/tiled/TMXGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXLayer.js +31 -31
- package/dist/melonjs.mjs/level/tiled/TMXObject.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTile.js +8 -8
- package/dist/melonjs.mjs/level/tiled/TMXTileMap.js +19 -19
- package/dist/melonjs.mjs/level/tiled/TMXTileset.js +15 -15
- package/dist/melonjs.mjs/level/tiled/TMXTilesetGroup.js +3 -3
- package/dist/melonjs.mjs/level/tiled/TMXUtils.js +46 -41
- package/dist/melonjs.mjs/level/tiled/constants.js +1 -1
- package/dist/melonjs.mjs/level/tiled/renderer/TMXHexagonalRenderer.js +30 -30
- package/dist/melonjs.mjs/level/tiled/renderer/TMXIsometricRenderer.js +21 -21
- package/dist/melonjs.mjs/level/tiled/renderer/TMXOrthogonalRenderer.js +10 -10
- package/dist/melonjs.mjs/level/tiled/renderer/TMXRenderer.js +2 -2
- package/dist/melonjs.mjs/level/tiled/renderer/TMXStaggeredRenderer.js +6 -6
- 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 +7 -7
- package/dist/melonjs.mjs/loader/loadingscreen.js +2 -2
- package/dist/melonjs.mjs/loader/melonjs_logo.png.js +1 -1
- package/dist/melonjs.mjs/loader/parser.js +13 -13
- package/dist/melonjs.mjs/loader/settings.js +3 -3
- package/dist/melonjs.mjs/math/color.js +25 -24
- package/dist/melonjs.mjs/math/math.js +2 -2
- package/dist/melonjs.mjs/math/matrix2.js +22 -22
- package/dist/melonjs.mjs/math/matrix3.js +52 -52
- package/dist/melonjs.mjs/math/observable_vector2.js +12 -12
- package/dist/melonjs.mjs/math/observable_vector3.js +22 -22
- package/dist/melonjs.mjs/math/vector2.js +11 -11
- package/dist/melonjs.mjs/math/vector3.js +21 -21
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/arraymultimap.js +45 -0
- package/dist/melonjs.mjs/node_modules/@teppeis/multimaps/dist/esm/multimap.js +130 -0
- 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 +2 -2
- 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 +5 -5
- package/dist/melonjs.mjs/particles/particle.js +8 -8
- package/dist/melonjs.mjs/particles/settings.js +3 -3
- package/dist/melonjs.mjs/physics/body.js +17 -17
- package/dist/melonjs.mjs/physics/bounds.js +12 -12
- package/dist/melonjs.mjs/physics/collision.js +3 -3
- package/dist/melonjs.mjs/physics/detector.js +14 -14
- package/dist/melonjs.mjs/physics/quadtree.js +19 -19
- package/dist/melonjs.mjs/physics/response.js +1 -1
- package/dist/melonjs.mjs/physics/sat.js +60 -60
- package/dist/melonjs.mjs/physics/world.js +4 -4
- package/dist/melonjs.mjs/plugin/plugin.js +11 -11
- package/dist/melonjs.mjs/renderable/collectable.js +2 -2
- package/dist/melonjs.mjs/renderable/colorlayer.js +1 -1
- package/dist/melonjs.mjs/renderable/container.js +77 -59
- package/dist/melonjs.mjs/renderable/dragndrop.js +5 -5
- package/dist/melonjs.mjs/renderable/imagelayer.js +7 -6
- package/dist/melonjs.mjs/renderable/light2d.js +6 -6
- package/dist/melonjs.mjs/renderable/nineslicesprite.js +12 -12
- package/dist/melonjs.mjs/renderable/renderable.js +35 -13
- package/dist/melonjs.mjs/renderable/sprite.js +25 -25
- package/dist/melonjs.mjs/renderable/trigger.js +11 -9
- package/dist/melonjs.mjs/renderable/ui/uibaseelement.js +97 -27
- package/dist/melonjs.mjs/renderable/ui/uispriteelement.js +25 -25
- package/dist/melonjs.mjs/renderable/ui/uitextbutton.js +83 -65
- package/dist/melonjs.mjs/state/stage.js +7 -7
- package/dist/melonjs.mjs/state/state.js +15 -15
- package/dist/melonjs.mjs/system/device.js +3 -3
- package/dist/melonjs.mjs/system/dom.js +1 -1
- package/dist/melonjs.mjs/system/event.js +2 -2
- package/dist/melonjs.mjs/system/platform.js +1 -1
- package/dist/melonjs.mjs/system/pooling.js +9 -9
- package/dist/melonjs.mjs/system/save.js +6 -6
- package/dist/melonjs.mjs/system/timer.js +16 -12
- package/dist/melonjs.mjs/text/bitmaptext.js +20 -20
- package/dist/melonjs.mjs/text/bitmaptextdata.js +22 -22
- package/dist/melonjs.mjs/text/glyph.js +3 -3
- package/dist/melonjs.mjs/text/text.js +63 -92
- package/dist/melonjs.mjs/text/textmetrics.js +15 -15
- package/dist/melonjs.mjs/text/textstyle.js +4 -6
- package/dist/melonjs.mjs/tweens/easing.js +4 -4
- package/dist/melonjs.mjs/tweens/interpolation.js +8 -8
- package/dist/melonjs.mjs/tweens/tween.js +11 -11
- package/dist/melonjs.mjs/utils/agent.js +6 -6
- package/dist/melonjs.mjs/utils/array.js +4 -4
- package/dist/melonjs.mjs/utils/file.js +1 -1
- package/dist/melonjs.mjs/utils/function.js +5 -5
- package/dist/melonjs.mjs/utils/string.js +3 -3
- package/dist/melonjs.mjs/utils/utils.js +16 -16
- package/dist/melonjs.mjs/video/canvas/canvas_renderer.js +41 -119
- package/dist/melonjs.mjs/video/renderer.js +70 -14
- package/dist/melonjs.mjs/video/texture/atlas.js +39 -45
- package/dist/melonjs.mjs/video/texture/cache.js +9 -10
- package/dist/melonjs.mjs/video/texture/canvas_texture.js +63 -3
- 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 +23 -19
- package/dist/melonjs.mjs/video/webgl/compositors/compositor.js +80 -80
- package/dist/melonjs.mjs/video/webgl/compositors/primitive_compositor.js +77 -0
- package/dist/melonjs.mjs/video/webgl/compositors/quad_compositor.js +252 -0
- package/dist/melonjs.mjs/video/webgl/compositors/webgl_compositor.js +1 -1
- package/dist/melonjs.mjs/video/webgl/glshader.js +7 -7
- 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 +2 -2
- package/dist/melonjs.mjs/video/webgl/utils/precision.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/program.js +7 -7
- package/dist/melonjs.mjs/video/webgl/utils/string.js +1 -1
- package/dist/melonjs.mjs/video/webgl/utils/uniforms.js +4 -4
- package/dist/melonjs.mjs/video/webgl/webgl_renderer.js +188 -181
- package/dist/melonjs.module.js +25040 -25193
- package/dist/types/application/application.d.ts +11 -8
- package/dist/types/audio/audio.d.ts +3 -3
- package/dist/types/entity/entity.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/input/input.d.ts +1 -1
- package/dist/types/input/keyboard.d.ts +1 -1
- package/dist/types/input/pointerevent.d.ts +6 -6
- package/dist/types/level/level.d.ts +2 -2
- package/dist/types/level/tiled/TMXLayer.d.ts +4 -4
- package/dist/types/level/tiled/TMXTileMap.d.ts +2 -2
- package/dist/types/level/tiled/TMXUtils.d.ts +5 -4
- package/dist/types/loader/loader.d.ts +2 -2
- package/dist/types/loader/settings.d.ts +2 -2
- package/dist/types/particles/emitter.d.ts +1 -1
- package/dist/types/physics/collision.d.ts +1 -1
- package/dist/types/physics/detector.d.ts +1 -1
- package/dist/types/plugin/plugin.d.ts +2 -2
- package/dist/types/renderable/container.d.ts +21 -17
- package/dist/types/renderable/renderable.d.ts +6 -0
- package/dist/types/renderable/sprite.d.ts +11 -11
- package/dist/types/renderable/trigger.d.ts +1 -1
- package/dist/types/renderable/ui/uibaseelement.d.ts +28 -6
- package/dist/types/renderable/ui/uispriteelement.d.ts +12 -14
- package/dist/types/renderable/ui/uitextbutton.d.ts +52 -12
- package/dist/types/state/stage.d.ts +1 -1
- package/dist/types/system/device.d.ts +1 -1
- package/dist/types/system/pooling.d.ts +3 -3
- package/dist/types/system/timer.d.ts +5 -5
- package/dist/types/text/bitmaptext.d.ts +1 -1
- package/dist/types/text/text.d.ts +7 -21
- package/dist/types/text/textstyle.d.ts +1 -1
- package/dist/types/utils/array.d.ts +2 -2
- package/dist/types/video/canvas/canvas_renderer.d.ts +8 -81
- package/dist/types/video/renderer.d.ts +48 -4
- package/dist/types/video/texture/atlas.d.ts +3 -3
- package/dist/types/video/texture/canvas_texture.d.ts +40 -0
- 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/glshader.d.ts +1 -1
- package/dist/types/video/webgl/webgl_renderer.d.ts +47 -37
- package/package.json +16 -17
- package/src/application/application.js +26 -16
- package/src/application/header.js +5 -4
- package/src/application/resize.js +19 -19
- package/src/audio/audio.js +17 -19
- package/src/camera/camera2d.js +9 -9
- package/src/entity/entity.js +3 -3
- package/src/geometries/ellipse.js +5 -5
- package/src/geometries/line.js +8 -8
- package/src/geometries/path2d.js +55 -55
- package/src/geometries/point.js +1 -1
- package/src/geometries/poly.js +28 -28
- package/src/geometries/rectangle.js +7 -7
- package/src/geometries/roundrect.js +5 -5
- package/src/index.js +9 -4
- package/src/input/gamepad.js +29 -29
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -14
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +52 -52
- package/src/lang/console.js +2 -2
- package/src/lang/deprecated.js +1 -1
- package/src/level/level.js +8 -8
- package/src/level/tiled/TMXGroup.js +2 -2
- package/src/level/tiled/TMXLayer.js +30 -30
- package/src/level/tiled/TMXObject.js +7 -7
- package/src/level/tiled/TMXTile.js +7 -7
- package/src/level/tiled/TMXTileMap.js +18 -18
- package/src/level/tiled/TMXTileset.js +14 -14
- package/src/level/tiled/TMXTilesetGroup.js +2 -2
- package/src/level/tiled/TMXUtils.js +45 -40
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +29 -29
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +20 -20
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +9 -9
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +5 -5
- package/src/loader/loader.js +6 -6
- package/src/loader/loadingscreen.js +1 -1
- package/src/loader/parser.js +12 -12
- package/src/loader/settings.js +2 -2
- package/src/math/color.js +24 -23
- package/src/math/math.js +1 -1
- package/src/math/matrix2.js +21 -21
- package/src/math/matrix3.js +51 -51
- package/src/math/observable_vector2.js +11 -11
- package/src/math/observable_vector3.js +21 -21
- package/src/math/vector2.js +10 -10
- package/src/math/vector3.js +20 -20
- package/src/particles/emitter.js +4 -4
- package/src/particles/particle.js +7 -7
- package/src/particles/settings.js +2 -2
- package/src/physics/body.js +16 -16
- package/src/physics/bounds.js +11 -11
- package/src/physics/collision.js +2 -2
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +18 -18
- package/src/physics/sat.js +59 -59
- package/src/physics/world.js +3 -3
- package/src/plugin/plugin.js +8 -8
- package/src/polyfill/index.js +0 -2
- package/src/renderable/collectable.js +1 -1
- package/src/renderable/container.js +76 -58
- package/src/renderable/dragndrop.js +4 -4
- package/src/renderable/imagelayer.js +6 -5
- package/src/renderable/light2d.js +5 -5
- package/src/renderable/nineslicesprite.js +11 -11
- package/src/renderable/renderable.js +34 -12
- package/src/renderable/sprite.js +24 -24
- package/src/renderable/trigger.js +10 -8
- package/src/renderable/ui/uibaseelement.js +96 -26
- package/src/renderable/ui/uispriteelement.js +24 -24
- package/src/renderable/ui/uitextbutton.js +85 -67
- package/src/state/stage.js +6 -6
- package/src/state/state.js +14 -14
- package/src/system/device.js +2 -2
- package/src/system/event.js +1 -1
- package/src/system/pooling.js +8 -8
- package/src/system/save.js +5 -5
- package/src/system/timer.js +15 -11
- package/src/text/bitmaptext.js +19 -19
- package/src/text/bitmaptextdata.js +21 -21
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +62 -91
- package/src/text/textmetrics.js +14 -14
- package/src/text/textstyle.js +3 -5
- package/src/tweens/easing.js +3 -3
- package/src/tweens/interpolation.js +7 -7
- package/src/tweens/tween.js +10 -10
- package/src/utils/agent.js +5 -5
- package/src/utils/array.js +3 -3
- package/src/utils/function.js +4 -4
- package/src/utils/string.js +2 -2
- package/src/utils/utils.js +15 -15
- package/src/video/canvas/canvas_renderer.js +39 -117
- package/src/video/renderer.js +68 -12
- package/src/video/texture/atlas.js +38 -44
- package/src/video/texture/cache.js +6 -6
- package/src/video/texture/canvas_texture.js +62 -2
- package/src/video/video.js +1 -1
- package/src/video/webgl/buffer/vertex.js +22 -18
- package/src/video/webgl/compositors/compositor.js +79 -80
- package/src/video/webgl/compositors/primitive_compositor.js +68 -0
- package/src/video/webgl/compositors/{webgl_compositor.js → quad_compositor.js} +52 -109
- package/src/video/webgl/glshader.js +6 -6
- package/src/video/webgl/shaders/primitive.vert +2 -5
- package/src/video/webgl/shaders/quad.vert +3 -1
- package/src/video/webgl/utils/attributes.js +1 -1
- package/src/video/webgl/utils/program.js +6 -6
- package/src/video/webgl/utils/uniforms.js +3 -3
- package/src/video/webgl/webgl_renderer.js +186 -179
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -39,7 +39,7 @@ import TextMetrics from './textmetrics.js';
|
|
|
39
39
|
* { name: "arial", type: "image" src: "data/font/arial.png" },
|
|
40
40
|
* ])
|
|
41
41
|
* // Then create an instance of your bitmap font:
|
|
42
|
-
*
|
|
42
|
+
* let myFont = new me.BitmapText(x, y, {font:"arial", text:"Hello"});
|
|
43
43
|
* // two possibilities for using "myFont"
|
|
44
44
|
* // either call the draw function from your Renderable draw function
|
|
45
45
|
* myFont.draw(renderer, "Hello!", 0, 0);
|
|
@@ -194,12 +194,12 @@ import TextMetrics from './textmetrics.js';
|
|
|
194
194
|
* @returns {Bounds} this Bitmap Text bounding box Rectangle object
|
|
195
195
|
*/
|
|
196
196
|
updateBounds(absolute = true) {
|
|
197
|
-
|
|
197
|
+
let bounds = this.getBounds();
|
|
198
198
|
|
|
199
199
|
bounds.clear();
|
|
200
200
|
|
|
201
201
|
if (typeof this.metrics !== "undefined") {
|
|
202
|
-
|
|
202
|
+
let ax, ay;
|
|
203
203
|
|
|
204
204
|
bounds.addBounds(this.metrics.measureText(this._text));
|
|
205
205
|
|
|
@@ -298,7 +298,7 @@ import TextMetrics from './textmetrics.js';
|
|
|
298
298
|
*/
|
|
299
299
|
draw(renderer, text, x, y) {
|
|
300
300
|
// save the previous global alpha value
|
|
301
|
-
|
|
301
|
+
let _alpha = renderer.globalAlpha();
|
|
302
302
|
|
|
303
303
|
// allows to provide backward compatibility when
|
|
304
304
|
// adding Bitmap Font to an object container
|
|
@@ -312,15 +312,15 @@ import TextMetrics from './textmetrics.js';
|
|
|
312
312
|
y = this.pos.y;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
let lX = x;
|
|
316
|
+
let stringHeight = this.metrics.lineHeight();
|
|
317
|
+
let maxWidth = 0;
|
|
318
318
|
|
|
319
|
-
for (
|
|
319
|
+
for (let i = 0; i < this._text.length; i++) {
|
|
320
320
|
x = lX;
|
|
321
|
-
|
|
321
|
+
let string = this._text[i].trimEnd();
|
|
322
322
|
// adjust x pos based on alignment value
|
|
323
|
-
|
|
323
|
+
let stringWidth = this.metrics.lineWidth(string);
|
|
324
324
|
switch (this.textAlign) {
|
|
325
325
|
case "right":
|
|
326
326
|
x -= stringWidth;
|
|
@@ -356,18 +356,18 @@ import TextMetrics from './textmetrics.js';
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
// draw the string
|
|
359
|
-
|
|
360
|
-
for (
|
|
359
|
+
let lastGlyph = null;
|
|
360
|
+
for (let c = 0, len = string.length; c < len; c++) {
|
|
361
361
|
// calculate the char index
|
|
362
|
-
|
|
363
|
-
|
|
362
|
+
let ch = string.charCodeAt(c);
|
|
363
|
+
let glyph = this.fontData.glyphs[ch];
|
|
364
364
|
|
|
365
365
|
if (typeof glyph !== "undefined") {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
366
|
+
let glyphWidth = glyph.width;
|
|
367
|
+
let glyphHeight = glyph.height;
|
|
368
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
369
|
+
let scaleX = this.fontScale.x;
|
|
370
|
+
let scaleY = this.fontScale.y;
|
|
371
371
|
|
|
372
372
|
// draw it
|
|
373
373
|
if (glyphWidth !== 0 && glyphHeight !== 0) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -15,7 +15,7 @@ const capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J
|
|
|
15
15
|
* @ignore
|
|
16
16
|
*/
|
|
17
17
|
function getValueFromPair(string, pattern) {
|
|
18
|
-
|
|
18
|
+
let value = string.match(pattern);
|
|
19
19
|
if (!value) {
|
|
20
20
|
throw new Error("Could not find pattern " + pattern + " in string: " + string);
|
|
21
21
|
}
|
|
@@ -32,8 +32,8 @@ function getValueFromPair(string, pattern) {
|
|
|
32
32
|
* @returns {Glyph}
|
|
33
33
|
*/
|
|
34
34
|
function getFirstGlyph(glyphs) {
|
|
35
|
-
|
|
36
|
-
for (
|
|
35
|
+
let keys = Object.keys(glyphs);
|
|
36
|
+
for (let i = 0; i < keys.length; i++) {
|
|
37
37
|
if (keys[i] > 32) {
|
|
38
38
|
return glyphs[keys[i]];
|
|
39
39
|
}
|
|
@@ -49,8 +49,8 @@ function getFirstGlyph(glyphs) {
|
|
|
49
49
|
* @param {object} glyphs - the map of glyphs, each key is a char code
|
|
50
50
|
*/
|
|
51
51
|
function createSpaceGlyph(glyphs) {
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
let spaceCharCode = " ".charCodeAt(0);
|
|
53
|
+
let glyph = glyphs[spaceCharCode];
|
|
54
54
|
if (!glyph) {
|
|
55
55
|
glyph = new Glyph();
|
|
56
56
|
glyph.id = spaceCharCode;
|
|
@@ -109,12 +109,12 @@ function createSpaceGlyph(glyphs) {
|
|
|
109
109
|
if (!fontData) {
|
|
110
110
|
throw new Error("File containing font data was empty, cannot load the bitmap font.");
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
let lines = fontData.split(/\r\n|\n/);
|
|
113
|
+
let padding = fontData.match(/padding\=\d+,\d+,\d+,\d+/g);
|
|
114
114
|
if (!padding) {
|
|
115
115
|
throw new Error("Padding not found in first line");
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
let paddingValues = padding[0].split("=")[1].split(",");
|
|
118
118
|
this.padTop = parseFloat(paddingValues[0]);
|
|
119
119
|
this.padLeft = parseFloat(paddingValues[1]);
|
|
120
120
|
this.padBottom = parseFloat(paddingValues[2]);
|
|
@@ -122,24 +122,24 @@ function createSpaceGlyph(glyphs) {
|
|
|
122
122
|
|
|
123
123
|
this.lineHeight = parseFloat(getValueFromPair(lines[1], /lineHeight\=\d+/g));
|
|
124
124
|
|
|
125
|
-
|
|
125
|
+
let baseLine = parseFloat(getValueFromPair(lines[1], /base\=\d+/g));
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
let padY = this.padTop + this.padBottom;
|
|
128
128
|
|
|
129
|
-
|
|
129
|
+
let glyph = null;
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
let i;
|
|
132
132
|
|
|
133
133
|
for (i = 4; i < lines.length; i++) {
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
let line = lines[i];
|
|
135
|
+
let characterValues = line.split(/=|\s+/);
|
|
136
136
|
if (!line || /^kernings/.test(line)) {
|
|
137
137
|
continue;
|
|
138
138
|
}
|
|
139
139
|
if (/^kerning\s/.test(line)) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
let first = parseFloat(characterValues[2]);
|
|
141
|
+
let second = parseFloat(characterValues[4]);
|
|
142
|
+
let amount = parseFloat(characterValues[6]);
|
|
143
143
|
|
|
144
144
|
glyph = this.glyphs[first];
|
|
145
145
|
if (glyph !== null && typeof glyph !== "undefined") {
|
|
@@ -148,7 +148,7 @@ function createSpaceGlyph(glyphs) {
|
|
|
148
148
|
} else {
|
|
149
149
|
glyph = new Glyph();
|
|
150
150
|
|
|
151
|
-
|
|
151
|
+
let ch = parseFloat(characterValues[2]);
|
|
152
152
|
glyph.id = ch;
|
|
153
153
|
glyph.x = parseFloat(characterValues[4]);
|
|
154
154
|
glyph.y = parseFloat(characterValues[6]);
|
|
@@ -170,16 +170,16 @@ function createSpaceGlyph(glyphs) {
|
|
|
170
170
|
|
|
171
171
|
createSpaceGlyph(this.glyphs);
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
let capGlyph = null;
|
|
174
174
|
for (i = 0; i < capChars.length; i++) {
|
|
175
|
-
|
|
175
|
+
let capChar = capChars[i];
|
|
176
176
|
capGlyph = this.glyphs[capChar.charCodeAt(0)];
|
|
177
177
|
if (capGlyph) {
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
if (!capGlyph) {
|
|
182
|
-
for (
|
|
182
|
+
for (let charCode in this.glyphs) {
|
|
183
183
|
if (this.glyphs.hasOwnProperty(charCode)) {
|
|
184
184
|
glyph = this.glyphs[charCode];
|
|
185
185
|
if (glyph.height === 0 || glyph.width === 0) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -38,7 +38,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
38
38
|
*/
|
|
39
39
|
getKerning(ch) {
|
|
40
40
|
if (this.kerning) {
|
|
41
|
-
|
|
41
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
42
42
|
if (page) {
|
|
43
43
|
return page[ch & PAGE_SIZE - 1] || 0;
|
|
44
44
|
}
|
|
@@ -53,7 +53,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
53
53
|
if (!this.kerning) {
|
|
54
54
|
this.kerning = {};
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
57
57
|
if (typeof page === "undefined") {
|
|
58
58
|
this.kerning[ch >>> LOG2_PAGE_SIZE] = {};
|
|
59
59
|
page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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,16 +39,15 @@ 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
|
|
64
|
-
*
|
|
50
|
+
* let font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
65
51
|
*/
|
|
66
52
|
constructor(x, y, settings) {
|
|
67
53
|
// call the parent constructor
|
|
@@ -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,9 @@ var getContext2d = function (renderer$1, text) {
|
|
|
199
175
|
this.italic();
|
|
200
176
|
}
|
|
201
177
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
178
|
+
// the canvas Texture used to render this text
|
|
179
|
+
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
|
|
180
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });
|
|
206
181
|
|
|
207
182
|
// instance to text metrics functions
|
|
208
183
|
this.metrics = new TextMetrics(this);
|
|
@@ -242,7 +217,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
242
217
|
*/
|
|
243
218
|
setFont(font, size = 10) {
|
|
244
219
|
// font name and type
|
|
245
|
-
|
|
220
|
+
let font_names = font.split(",").map((value) => {
|
|
246
221
|
value = value.trim();
|
|
247
222
|
return (
|
|
248
223
|
!/(^".*"$)|(^'.*'$)/.test(value)
|
|
@@ -255,7 +230,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
255
230
|
size += "px";
|
|
256
231
|
} else /* string */ {
|
|
257
232
|
// extract the units and convert if necessary
|
|
258
|
-
|
|
233
|
+
let CSSval = size.match(/([-+]?[\d.]*)(.*)/);
|
|
259
234
|
this.fontSize = parseFloat(CSSval[1]);
|
|
260
235
|
if (CSSval[2]) {
|
|
261
236
|
this.fontSize *= toPX[runits.indexOf(CSSval[2])];
|
|
@@ -278,7 +253,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
278
253
|
* @returns {Text} this object for chaining
|
|
279
254
|
*/
|
|
280
255
|
setText(value = "") {
|
|
281
|
-
|
|
256
|
+
let bounds = this.getBounds();
|
|
282
257
|
|
|
283
258
|
// set the next text
|
|
284
259
|
if (this._text.toString() !== value.toString()) {
|
|
@@ -291,38 +266,38 @@ var getContext2d = function (renderer$1, text) {
|
|
|
291
266
|
|
|
292
267
|
// word wrap if necessary
|
|
293
268
|
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
294
|
-
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth,
|
|
269
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
|
|
295
270
|
}
|
|
296
271
|
|
|
297
272
|
// calculcate the text size and update the bounds accordingly
|
|
298
|
-
bounds.addBounds(this.metrics.measureText(this._text,
|
|
273
|
+
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
299
274
|
|
|
300
275
|
// 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);
|
|
276
|
+
let width = Math.ceil(this.metrics.width),
|
|
277
|
+
height = Math.ceil(this.metrics.height);
|
|
278
|
+
|
|
279
|
+
if (typeof renderer.gl !== "undefined") {
|
|
280
|
+
// make sure the right compositor is active
|
|
281
|
+
renderer.setCompositor("quad");
|
|
282
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
283
|
+
this.glTextureUnit = renderer.cache.getUnit(renderer.cache.get(this.canvasTexture.canvas));
|
|
284
|
+
renderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
285
|
+
|
|
286
|
+
if (renderer.WebGLVersion === 1) {
|
|
287
|
+
// round size to next Pow2
|
|
288
|
+
width = nextPowerOfTwo(this.metrics.width);
|
|
289
|
+
height = nextPowerOfTwo(this.metrics.height);
|
|
320
290
|
}
|
|
291
|
+
}
|
|
321
292
|
|
|
322
|
-
|
|
323
|
-
|
|
293
|
+
// resize the cache canvas if necessary
|
|
294
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
295
|
+
this.canvasTexture.resize(width, height);
|
|
324
296
|
}
|
|
325
297
|
|
|
298
|
+
this.canvasTexture.clear();
|
|
299
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
|
|
300
|
+
|
|
326
301
|
this.isDirty = true;
|
|
327
302
|
|
|
328
303
|
return this;
|
|
@@ -335,7 +310,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
335
310
|
* @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
|
|
336
311
|
*/
|
|
337
312
|
measureText(renderer, text = this._text) {
|
|
338
|
-
return this.metrics.measureText(text,
|
|
313
|
+
return this.metrics.measureText(text, this.canvasTexture.context);
|
|
339
314
|
}
|
|
340
315
|
|
|
341
316
|
|
|
@@ -345,9 +320,8 @@ var getContext2d = function (renderer$1, text) {
|
|
|
345
320
|
* @param {string} [text]
|
|
346
321
|
* @param {number} [x]
|
|
347
322
|
* @param {number} [y]
|
|
348
|
-
* @param {boolean} [stroke=false] - draw stroke the the text if true
|
|
349
323
|
*/
|
|
350
|
-
draw(renderer, text, x = this.pos.x, y = this.pos.y
|
|
324
|
+
draw(renderer, text, x = this.pos.x, y = this.pos.y) {
|
|
351
325
|
// "hacky patch" for backward compatibilty
|
|
352
326
|
if (typeof this.ancestor === "undefined") {
|
|
353
327
|
|
|
@@ -361,21 +335,18 @@ var getContext2d = function (renderer$1, text) {
|
|
|
361
335
|
// update text cache
|
|
362
336
|
this.setText(text);
|
|
363
337
|
|
|
364
|
-
x = this.metrics.x;
|
|
365
|
-
y = this.metrics.y;
|
|
366
|
-
|
|
367
338
|
// save the previous context
|
|
368
339
|
renderer.save();
|
|
369
340
|
|
|
370
341
|
// apply the defined alpha value
|
|
371
342
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
372
343
|
|
|
373
|
-
} else {
|
|
374
|
-
// added directly to an object container
|
|
375
|
-
x = this.pos.x;
|
|
376
|
-
y = this.pos.y;
|
|
377
344
|
}
|
|
378
345
|
|
|
346
|
+
// adjust x,y position based on the bounding box
|
|
347
|
+
x = this.metrics.x;
|
|
348
|
+
y = this.metrics.y;
|
|
349
|
+
|
|
379
350
|
// clamp to pixel grid if required
|
|
380
351
|
if (renderer.settings.subPixel === false) {
|
|
381
352
|
x = ~~x;
|
|
@@ -383,12 +354,7 @@ var getContext2d = function (renderer$1, text) {
|
|
|
383
354
|
}
|
|
384
355
|
|
|
385
356
|
// 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
|
-
|
|
357
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
392
358
|
|
|
393
359
|
// for backward compatibilty
|
|
394
360
|
if (typeof this.ancestor === "undefined") {
|
|
@@ -398,28 +364,33 @@ var getContext2d = function (renderer$1, text) {
|
|
|
398
364
|
}
|
|
399
365
|
|
|
400
366
|
/**
|
|
401
|
-
* draw a stroke text at the specified coord, as defined
|
|
402
|
-
*
|
|
403
|
-
* Note : using drawStroke is not recommended for performance reasons
|
|
367
|
+
* draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
|
|
368
|
+
* @deprecated since 15.0.0
|
|
404
369
|
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
405
370
|
* @param {string} text
|
|
406
371
|
* @param {number} x
|
|
407
372
|
* @param {number} y
|
|
408
373
|
*/
|
|
409
374
|
drawStroke(renderer, text, x, y) {
|
|
410
|
-
this.draw(renderer, text, x, y
|
|
375
|
+
this.draw(renderer, text, x, y);
|
|
411
376
|
}
|
|
412
377
|
|
|
413
378
|
/**
|
|
414
379
|
* @ignore
|
|
415
380
|
*/
|
|
416
|
-
_drawFont(context, text, x, y
|
|
417
|
-
setContextStyle(context, this
|
|
381
|
+
_drawFont(context, text, x, y) {
|
|
382
|
+
setContextStyle(context, this);
|
|
418
383
|
|
|
419
|
-
for (
|
|
420
|
-
|
|
384
|
+
for (let i = 0; i < text.length; i++) {
|
|
385
|
+
let string = text[i].trimEnd();
|
|
421
386
|
// draw the string
|
|
422
|
-
|
|
387
|
+
if (this.fillStyle.alpha > 0) {
|
|
388
|
+
context.fillText(string, x, y);
|
|
389
|
+
}
|
|
390
|
+
// stroke the text
|
|
391
|
+
if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
|
|
392
|
+
context.strokeText(string, x, y);
|
|
393
|
+
}
|
|
423
394
|
// add leading space
|
|
424
395
|
y += this.metrics.lineHeight();
|
|
425
396
|
}
|
|
@@ -431,15 +402,15 @@ var getContext2d = function (renderer$1, text) {
|
|
|
431
402
|
* @ignore
|
|
432
403
|
*/
|
|
433
404
|
destroy() {
|
|
434
|
-
if (
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
renderer.cache.delete(this.canvasTexture.canvas);
|
|
440
|
-
pool.push(this.canvasTexture);
|
|
441
|
-
this.canvasTexture = undefined;
|
|
405
|
+
if (typeof renderer.gl !== "undefined") {
|
|
406
|
+
// make sure the right compositor is active
|
|
407
|
+
renderer.setCompositor("quad");
|
|
408
|
+
renderer.currentCompositor.deleteTexture2D(renderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
409
|
+
this.glTextureUnit = undefined;
|
|
442
410
|
}
|
|
411
|
+
renderer.cache.delete(this.canvasTexture.canvas);
|
|
412
|
+
pool.push(this.canvasTexture);
|
|
413
|
+
this.canvasTexture = undefined;
|
|
443
414
|
pool.push(this.fillStyle);
|
|
444
415
|
pool.push(this.strokeStyle);
|
|
445
416
|
this.fillStyle = this.strokeStyle = undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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
|
|
@@ -57,14 +57,14 @@ import setContextStyle from './textstyle.js';
|
|
|
57
57
|
if (this.ancestor instanceof Text) {
|
|
58
58
|
return context.measureText(text).width;
|
|
59
59
|
} else { // it's a BitmapText
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
for (
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
let characters = text.split("");
|
|
61
|
+
let width = 0;
|
|
62
|
+
let lastGlyph = null;
|
|
63
|
+
for (let i = 0; i < characters.length; i++) {
|
|
64
|
+
let ch = characters[i].charCodeAt(0);
|
|
65
|
+
let glyph = this.ancestor.fontData.glyphs[ch];
|
|
66
66
|
if (typeof glyph !== "undefined") {
|
|
67
|
-
|
|
67
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
68
68
|
width += (glyph.xadvance + kerning) * this.ancestor.fontScale.x;
|
|
69
69
|
lastGlyph = glyph;
|
|
70
70
|
}
|
|
@@ -80,7 +80,7 @@ import setContextStyle from './textstyle.js';
|
|
|
80
80
|
* @returns {TextMetrics} this
|
|
81
81
|
*/
|
|
82
82
|
measureText(text, context) {
|
|
83
|
-
|
|
83
|
+
let strings;
|
|
84
84
|
|
|
85
85
|
if (!Array.isArray(text)) {
|
|
86
86
|
strings = ("" + text).split("\n");
|
|
@@ -99,7 +99,7 @@ import setContextStyle from './textstyle.js';
|
|
|
99
99
|
// compute the bounding box size
|
|
100
100
|
this.width = this.height = 0;
|
|
101
101
|
|
|
102
|
-
for (
|
|
102
|
+
for (let i = 0; i < strings.length; i++) {
|
|
103
103
|
this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
|
|
104
104
|
this.height += this.lineHeight();
|
|
105
105
|
}
|
|
@@ -130,9 +130,9 @@ import setContextStyle from './textstyle.js';
|
|
|
130
130
|
* @returns {string[]} an array of string representing wrapped text
|
|
131
131
|
*/
|
|
132
132
|
wordWrap(text, width, context) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
let words;
|
|
134
|
+
let currentLine = "";
|
|
135
|
+
let output = [];
|
|
136
136
|
|
|
137
137
|
if (Array.isArray(text)) {
|
|
138
138
|
// join into a single string
|
|
@@ -150,8 +150,8 @@ import setContextStyle from './textstyle.js';
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
for (let i = 0; i < words.length; i++) {
|
|
153
|
-
|
|
154
|
-
|
|
153
|
+
let word = words[i];
|
|
154
|
+
let lineWidth = this.lineWidth(currentLine + word + " ", context);
|
|
155
155
|
if (lineWidth < width) {
|
|
156
156
|
// add the word to the current line
|
|
157
157
|
currentLine += word + " ";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* melonJS Game Engine -
|
|
2
|
+
* melonJS Game Engine - v15.1.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.1.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
|
|
@@ -270,21 +270,21 @@ let Easing = {
|
|
|
270
270
|
/** @ignore */
|
|
271
271
|
In: function ( k ) {
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
const s = 1.70158;
|
|
274
274
|
return k * k * ( ( s + 1 ) * k - s );
|
|
275
275
|
|
|
276
276
|
},
|
|
277
277
|
/** @ignore */
|
|
278
278
|
Out: function ( k ) {
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
const s = 1.70158;
|
|
281
281
|
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
|
282
282
|
|
|
283
283
|
},
|
|
284
284
|
/** @ignore */
|
|
285
285
|
InOut: function ( k ) {
|
|
286
286
|
|
|
287
|
-
|
|
287
|
+
const s = 1.70158 * 1.525;
|
|
288
288
|
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
|
289
289
|
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
|
290
290
|
|