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
|
@@ -8,7 +8,7 @@ const capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J
|
|
|
8
8
|
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
function getValueFromPair(string, pattern) {
|
|
11
|
-
|
|
11
|
+
let value = string.match(pattern);
|
|
12
12
|
if (!value) {
|
|
13
13
|
throw new Error("Could not find pattern " + pattern + " in string: " + string);
|
|
14
14
|
}
|
|
@@ -25,8 +25,8 @@ function getValueFromPair(string, pattern) {
|
|
|
25
25
|
* @returns {Glyph}
|
|
26
26
|
*/
|
|
27
27
|
function getFirstGlyph(glyphs) {
|
|
28
|
-
|
|
29
|
-
for (
|
|
28
|
+
let keys = Object.keys(glyphs);
|
|
29
|
+
for (let i = 0; i < keys.length; i++) {
|
|
30
30
|
if (keys[i] > 32) {
|
|
31
31
|
return glyphs[keys[i]];
|
|
32
32
|
}
|
|
@@ -42,8 +42,8 @@ function getFirstGlyph(glyphs) {
|
|
|
42
42
|
* @param {object} glyphs - the map of glyphs, each key is a char code
|
|
43
43
|
*/
|
|
44
44
|
function createSpaceGlyph(glyphs) {
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
let spaceCharCode = " ".charCodeAt(0);
|
|
46
|
+
let glyph = glyphs[spaceCharCode];
|
|
47
47
|
if (!glyph) {
|
|
48
48
|
glyph = new Glyph();
|
|
49
49
|
glyph.id = spaceCharCode;
|
|
@@ -102,12 +102,12 @@ function createSpaceGlyph(glyphs) {
|
|
|
102
102
|
if (!fontData) {
|
|
103
103
|
throw new Error("File containing font data was empty, cannot load the bitmap font.");
|
|
104
104
|
}
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
let lines = fontData.split(/\r\n|\n/);
|
|
106
|
+
let padding = fontData.match(/padding\=\d+,\d+,\d+,\d+/g);
|
|
107
107
|
if (!padding) {
|
|
108
108
|
throw new Error("Padding not found in first line");
|
|
109
109
|
}
|
|
110
|
-
|
|
110
|
+
let paddingValues = padding[0].split("=")[1].split(",");
|
|
111
111
|
this.padTop = parseFloat(paddingValues[0]);
|
|
112
112
|
this.padLeft = parseFloat(paddingValues[1]);
|
|
113
113
|
this.padBottom = parseFloat(paddingValues[2]);
|
|
@@ -115,24 +115,24 @@ function createSpaceGlyph(glyphs) {
|
|
|
115
115
|
|
|
116
116
|
this.lineHeight = parseFloat(getValueFromPair(lines[1], /lineHeight\=\d+/g));
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
let baseLine = parseFloat(getValueFromPair(lines[1], /base\=\d+/g));
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
let padY = this.padTop + this.padBottom;
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
let glyph = null;
|
|
123
123
|
|
|
124
|
-
|
|
124
|
+
let i;
|
|
125
125
|
|
|
126
126
|
for (i = 4; i < lines.length; i++) {
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
let line = lines[i];
|
|
128
|
+
let characterValues = line.split(/=|\s+/);
|
|
129
129
|
if (!line || /^kernings/.test(line)) {
|
|
130
130
|
continue;
|
|
131
131
|
}
|
|
132
132
|
if (/^kerning\s/.test(line)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
let first = parseFloat(characterValues[2]);
|
|
134
|
+
let second = parseFloat(characterValues[4]);
|
|
135
|
+
let amount = parseFloat(characterValues[6]);
|
|
136
136
|
|
|
137
137
|
glyph = this.glyphs[first];
|
|
138
138
|
if (glyph !== null && typeof glyph !== "undefined") {
|
|
@@ -141,7 +141,7 @@ function createSpaceGlyph(glyphs) {
|
|
|
141
141
|
} else {
|
|
142
142
|
glyph = new Glyph();
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
let ch = parseFloat(characterValues[2]);
|
|
145
145
|
glyph.id = ch;
|
|
146
146
|
glyph.x = parseFloat(characterValues[4]);
|
|
147
147
|
glyph.y = parseFloat(characterValues[6]);
|
|
@@ -163,16 +163,16 @@ function createSpaceGlyph(glyphs) {
|
|
|
163
163
|
|
|
164
164
|
createSpaceGlyph(this.glyphs);
|
|
165
165
|
|
|
166
|
-
|
|
166
|
+
let capGlyph = null;
|
|
167
167
|
for (i = 0; i < capChars.length; i++) {
|
|
168
|
-
|
|
168
|
+
let capChar = capChars[i];
|
|
169
169
|
capGlyph = this.glyphs[capChar.charCodeAt(0)];
|
|
170
170
|
if (capGlyph) {
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
if (!capGlyph) {
|
|
175
|
-
for (
|
|
175
|
+
for (let charCode in this.glyphs) {
|
|
176
176
|
if (this.glyphs.hasOwnProperty(charCode)) {
|
|
177
177
|
glyph = this.glyphs[charCode];
|
|
178
178
|
if (glyph.height === 0 || glyph.width === 0) {
|
package/src/text/glyph.js
CHANGED
|
@@ -32,7 +32,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
32
32
|
*/
|
|
33
33
|
getKerning(ch) {
|
|
34
34
|
if (this.kerning) {
|
|
35
|
-
|
|
35
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
36
36
|
if (page) {
|
|
37
37
|
return page[ch & PAGE_SIZE - 1] || 0;
|
|
38
38
|
}
|
|
@@ -47,7 +47,7 @@ const PAGE_SIZE = 1 << LOG2_PAGE_SIZE;
|
|
|
47
47
|
if (!this.kerning) {
|
|
48
48
|
this.kerning = {};
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
let page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
|
51
51
|
if (typeof page === "undefined") {
|
|
52
52
|
this.kerning[ch >>> LOG2_PAGE_SIZE] = {};
|
|
53
53
|
page = this.kerning[ch >>> LOG2_PAGE_SIZE];
|
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,16 +32,15 @@ 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
|
|
57
|
-
*
|
|
43
|
+
* let font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
58
44
|
*/
|
|
59
45
|
constructor(x, y, settings) {
|
|
60
46
|
// call the parent constructor
|
|
@@ -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,9 @@ var getContext2d = function (renderer, text) {
|
|
|
192
168
|
this.italic();
|
|
193
169
|
}
|
|
194
170
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
171
|
+
// the canvas Texture used to render this text
|
|
172
|
+
// XXX: offscreenCanvas is currently disabled for text rendering due to issue in WebGL mode
|
|
173
|
+
this.canvasTexture = pool.pull("CanvasTexture", 2, 2, { offscreenCanvas: false });
|
|
199
174
|
|
|
200
175
|
// instance to text metrics functions
|
|
201
176
|
this.metrics = new TextMetrics(this);
|
|
@@ -235,7 +210,7 @@ var getContext2d = function (renderer, text) {
|
|
|
235
210
|
*/
|
|
236
211
|
setFont(font, size = 10) {
|
|
237
212
|
// font name and type
|
|
238
|
-
|
|
213
|
+
let font_names = font.split(",").map((value) => {
|
|
239
214
|
value = value.trim();
|
|
240
215
|
return (
|
|
241
216
|
!/(^".*"$)|(^'.*'$)/.test(value)
|
|
@@ -248,7 +223,7 @@ var getContext2d = function (renderer, text) {
|
|
|
248
223
|
size += "px";
|
|
249
224
|
} else /* string */ {
|
|
250
225
|
// extract the units and convert if necessary
|
|
251
|
-
|
|
226
|
+
let CSSval = size.match(/([-+]?[\d.]*)(.*)/);
|
|
252
227
|
this.fontSize = parseFloat(CSSval[1]);
|
|
253
228
|
if (CSSval[2]) {
|
|
254
229
|
this.fontSize *= toPX[runits.indexOf(CSSval[2])];
|
|
@@ -271,7 +246,7 @@ var getContext2d = function (renderer, text) {
|
|
|
271
246
|
* @returns {Text} this object for chaining
|
|
272
247
|
*/
|
|
273
248
|
setText(value = "") {
|
|
274
|
-
|
|
249
|
+
let bounds = this.getBounds();
|
|
275
250
|
|
|
276
251
|
// set the next text
|
|
277
252
|
if (this._text.toString() !== value.toString()) {
|
|
@@ -284,38 +259,38 @@ var getContext2d = function (renderer, text) {
|
|
|
284
259
|
|
|
285
260
|
// word wrap if necessary
|
|
286
261
|
if (this._text.length > 0 && this.wordWrapWidth > 0) {
|
|
287
|
-
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth,
|
|
262
|
+
this._text = this.metrics.wordWrap(this._text, this.wordWrapWidth, this.canvasTexture.context);
|
|
288
263
|
}
|
|
289
264
|
|
|
290
265
|
// calculcate the text size and update the bounds accordingly
|
|
291
|
-
bounds.addBounds(this.metrics.measureText(this._text,
|
|
266
|
+
bounds.addBounds(this.metrics.measureText(this._text, this.canvasTexture.context), true);
|
|
292
267
|
|
|
293
268
|
// 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);
|
|
269
|
+
let width = Math.ceil(this.metrics.width),
|
|
270
|
+
height = Math.ceil(this.metrics.height);
|
|
271
|
+
|
|
272
|
+
if (typeof globalRenderer.gl !== "undefined") {
|
|
273
|
+
// make sure the right compositor is active
|
|
274
|
+
globalRenderer.setCompositor("quad");
|
|
275
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
276
|
+
this.glTextureUnit = globalRenderer.cache.getUnit(globalRenderer.cache.get(this.canvasTexture.canvas));
|
|
277
|
+
globalRenderer.currentCompositor.unbindTexture2D(null, this.glTextureUnit);
|
|
278
|
+
|
|
279
|
+
if (globalRenderer.WebGLVersion === 1) {
|
|
280
|
+
// round size to next Pow2
|
|
281
|
+
width = nextPowerOfTwo(this.metrics.width);
|
|
282
|
+
height = nextPowerOfTwo(this.metrics.height);
|
|
313
283
|
}
|
|
284
|
+
}
|
|
314
285
|
|
|
315
|
-
|
|
316
|
-
|
|
286
|
+
// resize the cache canvas if necessary
|
|
287
|
+
if (this.canvasTexture.width < width || this.canvasTexture.height < height) {
|
|
288
|
+
this.canvasTexture.resize(width, height);
|
|
317
289
|
}
|
|
318
290
|
|
|
291
|
+
this.canvasTexture.clear();
|
|
292
|
+
this._drawFont(this.canvasTexture.context, this._text, this.pos.x - this.metrics.x, this.pos.y - this.metrics.y);
|
|
293
|
+
|
|
319
294
|
this.isDirty = true;
|
|
320
295
|
|
|
321
296
|
return this;
|
|
@@ -328,7 +303,7 @@ var getContext2d = function (renderer, text) {
|
|
|
328
303
|
* @returns {TextMetrics} a TextMetrics object defining the dimensions of the given piece of text
|
|
329
304
|
*/
|
|
330
305
|
measureText(renderer, text = this._text) {
|
|
331
|
-
return this.metrics.measureText(text,
|
|
306
|
+
return this.metrics.measureText(text, this.canvasTexture.context);
|
|
332
307
|
}
|
|
333
308
|
|
|
334
309
|
|
|
@@ -338,9 +313,8 @@ var getContext2d = function (renderer, text) {
|
|
|
338
313
|
* @param {string} [text]
|
|
339
314
|
* @param {number} [x]
|
|
340
315
|
* @param {number} [y]
|
|
341
|
-
* @param {boolean} [stroke=false] - draw stroke the the text if true
|
|
342
316
|
*/
|
|
343
|
-
draw(renderer, text, x = this.pos.x, y = this.pos.y
|
|
317
|
+
draw(renderer, text, x = this.pos.x, y = this.pos.y) {
|
|
344
318
|
// "hacky patch" for backward compatibilty
|
|
345
319
|
if (typeof this.ancestor === "undefined") {
|
|
346
320
|
|
|
@@ -354,21 +328,18 @@ var getContext2d = function (renderer, text) {
|
|
|
354
328
|
// update text cache
|
|
355
329
|
this.setText(text);
|
|
356
330
|
|
|
357
|
-
x = this.metrics.x;
|
|
358
|
-
y = this.metrics.y;
|
|
359
|
-
|
|
360
331
|
// save the previous context
|
|
361
332
|
renderer.save();
|
|
362
333
|
|
|
363
334
|
// apply the defined alpha value
|
|
364
335
|
renderer.setGlobalAlpha(renderer.globalAlpha() * this.getOpacity());
|
|
365
336
|
|
|
366
|
-
} else {
|
|
367
|
-
// added directly to an object container
|
|
368
|
-
x = this.pos.x;
|
|
369
|
-
y = this.pos.y;
|
|
370
337
|
}
|
|
371
338
|
|
|
339
|
+
// adjust x,y position based on the bounding box
|
|
340
|
+
x = this.metrics.x;
|
|
341
|
+
y = this.metrics.y;
|
|
342
|
+
|
|
372
343
|
// clamp to pixel grid if required
|
|
373
344
|
if (renderer.settings.subPixel === false) {
|
|
374
345
|
x = ~~x;
|
|
@@ -376,12 +347,7 @@ var getContext2d = function (renderer, text) {
|
|
|
376
347
|
}
|
|
377
348
|
|
|
378
349
|
// 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
|
-
|
|
350
|
+
renderer.drawImage(this.canvasTexture.canvas, x, y);
|
|
385
351
|
|
|
386
352
|
// for backward compatibilty
|
|
387
353
|
if (typeof this.ancestor === "undefined") {
|
|
@@ -391,28 +357,33 @@ var getContext2d = function (renderer, text) {
|
|
|
391
357
|
}
|
|
392
358
|
|
|
393
359
|
/**
|
|
394
|
-
* draw a stroke text at the specified coord, as defined
|
|
395
|
-
*
|
|
396
|
-
* Note : using drawStroke is not recommended for performance reasons
|
|
360
|
+
* draw a stroke text at the specified coord, as defined by the `lineWidth` and `fillStroke` properties.
|
|
361
|
+
* @deprecated since 15.0.0
|
|
397
362
|
* @param {CanvasRenderer|WebGLRenderer} renderer - Reference to the destination renderer instance
|
|
398
363
|
* @param {string} text
|
|
399
364
|
* @param {number} x
|
|
400
365
|
* @param {number} y
|
|
401
366
|
*/
|
|
402
367
|
drawStroke(renderer, text, x, y) {
|
|
403
|
-
this.draw(renderer, text, x, y
|
|
368
|
+
this.draw(renderer, text, x, y);
|
|
404
369
|
}
|
|
405
370
|
|
|
406
371
|
/**
|
|
407
372
|
* @ignore
|
|
408
373
|
*/
|
|
409
|
-
_drawFont(context, text, x, y
|
|
410
|
-
setContextStyle(context, this
|
|
374
|
+
_drawFont(context, text, x, y) {
|
|
375
|
+
setContextStyle(context, this);
|
|
411
376
|
|
|
412
|
-
for (
|
|
413
|
-
|
|
377
|
+
for (let i = 0; i < text.length; i++) {
|
|
378
|
+
let string = text[i].trimEnd();
|
|
414
379
|
// draw the string
|
|
415
|
-
|
|
380
|
+
if (this.fillStyle.alpha > 0) {
|
|
381
|
+
context.fillText(string, x, y);
|
|
382
|
+
}
|
|
383
|
+
// stroke the text
|
|
384
|
+
if (this.lineWidth > 0 && this.strokeStyle.alpha > 0) {
|
|
385
|
+
context.strokeText(string, x, y);
|
|
386
|
+
}
|
|
416
387
|
// add leading space
|
|
417
388
|
y += this.metrics.lineHeight();
|
|
418
389
|
}
|
|
@@ -424,15 +395,15 @@ var getContext2d = function (renderer, text) {
|
|
|
424
395
|
* @ignore
|
|
425
396
|
*/
|
|
426
397
|
destroy() {
|
|
427
|
-
if (
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
433
|
-
pool.push(this.canvasTexture);
|
|
434
|
-
this.canvasTexture = undefined;
|
|
398
|
+
if (typeof globalRenderer.gl !== "undefined") {
|
|
399
|
+
// make sure the right compositor is active
|
|
400
|
+
globalRenderer.setCompositor("quad");
|
|
401
|
+
globalRenderer.currentCompositor.deleteTexture2D(globalRenderer.currentCompositor.getTexture2D(this.glTextureUnit));
|
|
402
|
+
this.glTextureUnit = undefined;
|
|
435
403
|
}
|
|
404
|
+
globalRenderer.cache.delete(this.canvasTexture.canvas);
|
|
405
|
+
pool.push(this.canvasTexture);
|
|
406
|
+
this.canvasTexture = undefined;
|
|
436
407
|
pool.push(this.fillStyle);
|
|
437
408
|
pool.push(this.strokeStyle);
|
|
438
409
|
this.fillStyle = this.strokeStyle = undefined;
|
package/src/text/textmetrics.js
CHANGED
|
@@ -50,14 +50,14 @@ import setContextStyle from "./textstyle.js";
|
|
|
50
50
|
if (this.ancestor instanceof Text) {
|
|
51
51
|
return context.measureText(text).width;
|
|
52
52
|
} else { // it's a BitmapText
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
let characters = text.split("");
|
|
54
|
+
let width = 0;
|
|
55
|
+
let lastGlyph = null;
|
|
56
|
+
for (let i = 0; i < characters.length; i++) {
|
|
57
|
+
let ch = characters[i].charCodeAt(0);
|
|
58
|
+
let glyph = this.ancestor.fontData.glyphs[ch];
|
|
59
59
|
if (typeof glyph !== "undefined") {
|
|
60
|
-
|
|
60
|
+
let kerning = (lastGlyph && lastGlyph.kerning) ? lastGlyph.getKerning(ch) : 0;
|
|
61
61
|
width += (glyph.xadvance + kerning) * this.ancestor.fontScale.x;
|
|
62
62
|
lastGlyph = glyph;
|
|
63
63
|
}
|
|
@@ -73,7 +73,7 @@ import setContextStyle from "./textstyle.js";
|
|
|
73
73
|
* @returns {TextMetrics} this
|
|
74
74
|
*/
|
|
75
75
|
measureText(text, context) {
|
|
76
|
-
|
|
76
|
+
let strings;
|
|
77
77
|
|
|
78
78
|
if (!Array.isArray(text)) {
|
|
79
79
|
strings = ("" + text).split("\n");
|
|
@@ -92,7 +92,7 @@ import setContextStyle from "./textstyle.js";
|
|
|
92
92
|
// compute the bounding box size
|
|
93
93
|
this.width = this.height = 0;
|
|
94
94
|
|
|
95
|
-
for (
|
|
95
|
+
for (let i = 0; i < strings.length; i++) {
|
|
96
96
|
this.width = Math.max(this.lineWidth(strings[i].trimEnd(), context), this.width);
|
|
97
97
|
this.height += this.lineHeight();
|
|
98
98
|
}
|
|
@@ -123,9 +123,9 @@ import setContextStyle from "./textstyle.js";
|
|
|
123
123
|
* @returns {string[]} an array of string representing wrapped text
|
|
124
124
|
*/
|
|
125
125
|
wordWrap(text, width, context) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
let words;
|
|
127
|
+
let currentLine = "";
|
|
128
|
+
let output = [];
|
|
129
129
|
|
|
130
130
|
if (Array.isArray(text)) {
|
|
131
131
|
// join into a single string
|
|
@@ -143,8 +143,8 @@ import setContextStyle from "./textstyle.js";
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
for (let i = 0; i < words.length; i++) {
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
let word = words[i];
|
|
147
|
+
let lineWidth = this.lineWidth(currentLine + word + " ", context);
|
|
148
148
|
if (lineWidth < width) {
|
|
149
149
|
// add the word to the current line
|
|
150
150
|
currentLine += word + " ";
|
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
|
}
|
package/src/tweens/easing.js
CHANGED
|
@@ -263,21 +263,21 @@ export let Easing = {
|
|
|
263
263
|
/** @ignore */
|
|
264
264
|
In: function ( k ) {
|
|
265
265
|
|
|
266
|
-
|
|
266
|
+
const s = 1.70158;
|
|
267
267
|
return k * k * ( ( s + 1 ) * k - s );
|
|
268
268
|
|
|
269
269
|
},
|
|
270
270
|
/** @ignore */
|
|
271
271
|
Out: function ( k ) {
|
|
272
272
|
|
|
273
|
-
|
|
273
|
+
const s = 1.70158;
|
|
274
274
|
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
|
275
275
|
|
|
276
276
|
},
|
|
277
277
|
/** @ignore */
|
|
278
278
|
InOut: function ( k ) {
|
|
279
279
|
|
|
280
|
-
|
|
280
|
+
const s = 1.70158 * 1.525;
|
|
281
281
|
if ( ( k *= 2 ) < 1 ) return 0.5 * ( k * k * ( ( s + 1 ) * k - s ) );
|
|
282
282
|
return 0.5 * ( ( k -= 2 ) * k * ( ( s + 1 ) * k + s ) + 2 );
|
|
283
283
|
|
|
@@ -20,7 +20,7 @@ export let Interpolation = {
|
|
|
20
20
|
/** @ignore */
|
|
21
21
|
Linear: function ( v, k ) {
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
let m = v.length - 1, f = m * k, i = Math.floor( f ), fn = Interpolation.Utils.Linear;
|
|
24
24
|
|
|
25
25
|
if ( k < 0 ) return fn( v[ 0 ], v[ 1 ], f );
|
|
26
26
|
if ( k > 1 ) return fn( v[ m ], v[ m - 1 ], m - f );
|
|
@@ -31,7 +31,7 @@ export let Interpolation = {
|
|
|
31
31
|
/** @ignore */
|
|
32
32
|
Bezier: function ( v, k ) {
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
let b = 0, n = v.length - 1, pw = Math.pow, bn = Interpolation.Utils.Bernstein, i;
|
|
35
35
|
|
|
36
36
|
for ( i = 0; i <= n; i++ ) {
|
|
37
37
|
b += pw( 1 - k, n - i ) * pw( k, i ) * v[ i ] * bn( n, i );
|
|
@@ -43,7 +43,7 @@ export let Interpolation = {
|
|
|
43
43
|
/** @ignore */
|
|
44
44
|
CatmullRom: function ( v, k ) {
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
let m = v.length - 1, f = m * k, i = Math.floor( f ), fn = Interpolation.Utils.CatmullRom;
|
|
47
47
|
|
|
48
48
|
if ( v[ 0 ] === v[ m ] ) {
|
|
49
49
|
|
|
@@ -72,18 +72,18 @@ export let Interpolation = {
|
|
|
72
72
|
/** @ignore */
|
|
73
73
|
Bernstein: function ( n, i ) {
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
let fc = Interpolation.Utils.Factorial;
|
|
76
76
|
return fc( n ) / fc( i ) / fc( n - i );
|
|
77
77
|
|
|
78
78
|
},
|
|
79
79
|
/* @ignore */
|
|
80
80
|
Factorial: ( function () {
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
let a = [ 1 ];
|
|
83
83
|
|
|
84
84
|
return function ( n ) {
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
let s = 1, i;
|
|
87
87
|
if ( a[ n ] ) return a[ n ];
|
|
88
88
|
for ( i = n; i > 1; i-- ) s *= i;
|
|
89
89
|
a[ n ] = s;
|
|
@@ -95,7 +95,7 @@ export let Interpolation = {
|
|
|
95
95
|
/** @ignore */
|
|
96
96
|
CatmullRom: function ( p0, p1, p2, p3, t ) {
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
let v0 = ( p2 - p0 ) * 0.5, v1 = ( p3 - p1 ) * 0.5, t2 = t * t, t3 = t * t2;
|
|
99
99
|
return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
|
|
100
100
|
}
|
|
101
101
|
}
|
package/src/tweens/tween.js
CHANGED
|
@@ -82,7 +82,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
82
82
|
this.isRenderable = false;
|
|
83
83
|
|
|
84
84
|
// Set all starting values present on the target object
|
|
85
|
-
for (
|
|
85
|
+
for ( let field in object ) {
|
|
86
86
|
if (typeof object !== "object") {
|
|
87
87
|
this._valuesStart[ field ] = parseFloat(object[field]);
|
|
88
88
|
}
|
|
@@ -174,7 +174,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
174
174
|
|
|
175
175
|
this._startTime = time + this._delayTime;
|
|
176
176
|
|
|
177
|
-
for (
|
|
177
|
+
for ( let property in this._valuesEnd ) {
|
|
178
178
|
|
|
179
179
|
// check if an Array was provided as property value
|
|
180
180
|
if ( this._valuesEnd[ property ] instanceof Array ) {
|
|
@@ -350,9 +350,9 @@ import { Interpolation } from "./interpolation.js";
|
|
|
350
350
|
// the original Tween implementation expect
|
|
351
351
|
// a timestamp and not a time delta
|
|
352
352
|
this._tweenTimeTracker = (game.lastUpdate > this._tweenTimeTracker) ? game.lastUpdate : this._tweenTimeTracker + dt;
|
|
353
|
-
|
|
353
|
+
let time = this._tweenTimeTracker;
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
let property;
|
|
356
356
|
|
|
357
357
|
if ( time < this._startTime ) {
|
|
358
358
|
|
|
@@ -372,15 +372,15 @@ import { Interpolation } from "./interpolation.js";
|
|
|
372
372
|
|
|
373
373
|
}
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
let elapsed = ( time - this._startTime ) / this._duration;
|
|
376
376
|
elapsed = elapsed > 1 ? 1 : elapsed;
|
|
377
377
|
|
|
378
|
-
|
|
378
|
+
let value = this._easingFunction( elapsed );
|
|
379
379
|
|
|
380
380
|
for ( property in this._valuesEnd ) {
|
|
381
381
|
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
let start = this._valuesStart[ property ] || 0;
|
|
383
|
+
let end = this._valuesEnd[ property ];
|
|
384
384
|
|
|
385
385
|
if ( end instanceof Array ) {
|
|
386
386
|
|
|
@@ -424,7 +424,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
424
424
|
}
|
|
425
425
|
|
|
426
426
|
if (this._yoyo) {
|
|
427
|
-
|
|
427
|
+
let tmp = this._valuesStartRepeat[ property ];
|
|
428
428
|
this._valuesStartRepeat[ property ] = this._valuesEnd[ property ];
|
|
429
429
|
this._valuesEnd[ property ] = tmp;
|
|
430
430
|
}
|
|
@@ -450,7 +450,7 @@ import { Interpolation } from "./interpolation.js";
|
|
|
450
450
|
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
for (
|
|
453
|
+
for ( let i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
|
454
454
|
|
|
455
455
|
this._chainedTweens[ i ].start( time );
|
|
456
456
|
|