melonjs 10.1.0 → 10.2.2
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/README.md +6 -12
- package/dist/melonjs.js +3119 -2857
- package/dist/melonjs.min.js +3 -3
- package/dist/melonjs.module.d.ts +2590 -2490
- package/dist/melonjs.module.js +2698 -2470
- package/package.json +10 -11
- package/src/audio/audio.js +43 -43
- package/src/camera/camera2d.js +55 -77
- package/src/entity/draggable.js +18 -17
- package/src/entity/droptarget.js +19 -18
- package/src/entity/entity.js +22 -26
- package/src/game.js +3 -3
- package/src/index.js +15 -11
- package/src/input/gamepad.js +13 -13
- package/src/input/input.js +1 -1
- package/src/input/keyboard.js +14 -16
- package/src/input/pointer.js +42 -35
- package/src/input/pointerevent.js +25 -33
- package/src/lang/deprecated.js +3 -3
- package/src/level/level.js +24 -16
- package/src/level/tiled/TMXGroup.js +6 -6
- package/src/level/tiled/TMXLayer.js +31 -31
- package/src/level/tiled/TMXObject.js +19 -19
- package/src/level/tiled/TMXTile.js +11 -12
- package/src/level/tiled/TMXTileMap.js +23 -21
- package/src/level/tiled/TMXTileset.js +13 -13
- package/src/level/tiled/TMXTilesetGroup.js +4 -4
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +17 -17
- package/src/loader/loader.js +31 -27
- package/src/loader/loadingscreen.js +40 -72
- package/src/math/color.js +45 -64
- package/src/math/math.js +17 -17
- package/src/math/matrix2.js +46 -46
- package/src/math/matrix3.js +64 -64
- package/src/math/observable_vector2.js +45 -57
- package/src/math/observable_vector3.js +56 -70
- package/src/math/vector2.js +60 -59
- package/src/math/vector3.js +65 -64
- package/src/particles/emitter.js +53 -55
- package/src/particles/particle.js +1 -1
- package/src/physics/body.js +45 -51
- package/src/physics/bounds.js +36 -36
- package/src/physics/collision.js +15 -16
- package/src/physics/detector.js +10 -11
- package/src/physics/quadtree.js +19 -17
- package/src/physics/sat.js +17 -17
- package/src/physics/world.js +13 -10
- package/src/plugin/plugin.js +6 -6
- package/src/renderable/GUI.js +13 -18
- package/src/renderable/collectable.js +3 -3
- package/src/renderable/colorlayer.js +4 -4
- package/src/renderable/container.js +65 -46
- package/src/renderable/imagelayer.js +32 -31
- package/src/renderable/nineslicesprite.js +211 -0
- package/src/renderable/renderable.js +69 -67
- package/src/renderable/sprite.js +57 -43
- package/src/renderable/trigger.js +14 -15
- package/src/shapes/ellipse.js +27 -26
- package/src/shapes/line.js +8 -7
- package/src/shapes/poly.js +33 -31
- package/src/shapes/rectangle.js +50 -96
- package/src/state/stage.js +8 -8
- package/src/state/state.js +56 -56
- package/src/system/device.js +97 -84
- package/src/system/event.js +72 -72
- package/src/system/pooling.js +14 -14
- package/src/system/save.js +6 -3
- package/src/system/timer.js +20 -20
- package/src/text/bitmaptext.js +27 -33
- package/src/text/bitmaptextdata.js +9 -9
- package/src/text/text.js +118 -59
- package/src/tweens/easing.js +4 -4
- package/src/tweens/interpolation.js +4 -4
- package/src/tweens/tween.js +37 -27
- package/src/utils/agent.js +9 -8
- package/src/utils/array.js +4 -4
- package/src/utils/file.js +4 -4
- package/src/utils/function.js +5 -5
- package/src/utils/string.js +12 -12
- package/src/utils/utils.js +19 -19
- package/src/video/canvas/canvas_renderer.js +90 -90
- package/src/video/renderer.js +40 -39
- package/src/video/texture.js +85 -76
- package/src/video/texture_cache.js +11 -0
- package/src/video/video.js +30 -30
- package/src/video/webgl/buffer/vertex.js +9 -1
- package/src/video/webgl/glshader.js +20 -20
- package/src/video/webgl/webgl_compositor.js +47 -37
- package/src/video/webgl/webgl_renderer.js +104 -104
package/src/text/bitmaptext.js
CHANGED
|
@@ -38,18 +38,19 @@ var measureTextHeight = function(font) {
|
|
|
38
38
|
* @extends me.Renderable
|
|
39
39
|
* @memberOf me
|
|
40
40
|
* @constructor
|
|
41
|
-
* @param {
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {
|
|
50
|
-
* @param {
|
|
41
|
+
* @param {number} x position of the text object
|
|
42
|
+
* @param {number} y position of the text object
|
|
43
|
+
* @param {object} settings the text configuration
|
|
44
|
+
* @param {string|Image} settings.font a font name to identify the corresponing source image
|
|
45
|
+
* @param {string} [settings.fontData=settings.font] the bitmap font data corresponding name, or the bitmap font data itself
|
|
46
|
+
* @param {number} [settings.size] size a scaling ratio
|
|
47
|
+
* @param {me.Color|string} [settings.fillStyle] a CSS color value used to tint the bitmapText (@see me.BitmapText.tint)
|
|
48
|
+
* @param {number} [settings.lineWidth=1] line width, in pixels, when drawing stroke
|
|
49
|
+
* @param {string} [settings.textAlign="left"] horizontal text alignment
|
|
50
|
+
* @param {string} [settings.textBaseline="top"] the text baseline
|
|
51
|
+
* @param {number} [settings.lineHeight=1.0] line spacing height
|
|
51
52
|
* @param {me.Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
|
|
52
|
-
* @param {(
|
|
53
|
+
* @param {(string|string[])} [settings.text] a string, or an array of strings
|
|
53
54
|
* @example
|
|
54
55
|
* // Use me.loader.preload or me.loader.load to load assets
|
|
55
56
|
* me.loader.preload([
|
|
@@ -76,7 +77,7 @@ class BitmapText extends Renderable {
|
|
|
76
77
|
* Set the default text alignment (or justification),<br>
|
|
77
78
|
* possible values are "left", "right", and "center".
|
|
78
79
|
* @public
|
|
79
|
-
* @type
|
|
80
|
+
* @type {string}
|
|
80
81
|
* @default "left"
|
|
81
82
|
* @name textAlign
|
|
82
83
|
* @memberOf me.BitmapText
|
|
@@ -87,7 +88,7 @@ class BitmapText extends Renderable {
|
|
|
87
88
|
* Set the text baseline (e.g. the Y-coordinate for the draw operation), <br>
|
|
88
89
|
* possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"<br>
|
|
89
90
|
* @public
|
|
90
|
-
* @type
|
|
91
|
+
* @type {string}
|
|
91
92
|
* @default "top"
|
|
92
93
|
* @name textBaseline
|
|
93
94
|
* @memberOf me.BitmapText
|
|
@@ -98,7 +99,7 @@ class BitmapText extends Renderable {
|
|
|
98
99
|
* Set the line spacing height (when displaying multi-line strings). <br>
|
|
99
100
|
* Current font height will be multiplied with this value to set the line height.
|
|
100
101
|
* @public
|
|
101
|
-
* @type
|
|
102
|
+
* @type {number}
|
|
102
103
|
* @default 1.0
|
|
103
104
|
* @name lineHeight
|
|
104
105
|
* @memberOf me.BitmapText
|
|
@@ -108,7 +109,7 @@ class BitmapText extends Renderable {
|
|
|
108
109
|
/**
|
|
109
110
|
* the text to be displayed
|
|
110
111
|
* @private
|
|
111
|
-
* @type {
|
|
112
|
+
* @type {string[]}
|
|
112
113
|
* @name _text
|
|
113
114
|
* @memberOf me.BitmapText
|
|
114
115
|
*/
|
|
@@ -167,9 +168,9 @@ class BitmapText extends Renderable {
|
|
|
167
168
|
* @name set
|
|
168
169
|
* @memberOf me.BitmapText.prototype
|
|
169
170
|
* @function
|
|
170
|
-
* @param {
|
|
171
|
-
* @param {
|
|
172
|
-
* @
|
|
171
|
+
* @param {string} textAlign ("left", "center", "right")
|
|
172
|
+
* @param {number} [scale]
|
|
173
|
+
* @returns {me.BitmapText} this object for chaining
|
|
173
174
|
*/
|
|
174
175
|
set(textAlign, scale) {
|
|
175
176
|
this.textAlign = textAlign;
|
|
@@ -187,8 +188,8 @@ class BitmapText extends Renderable {
|
|
|
187
188
|
* @name setText
|
|
188
189
|
* @memberOf me.BitmapText.prototype
|
|
189
190
|
* @function
|
|
190
|
-
* @param {
|
|
191
|
-
* @
|
|
191
|
+
* @param {number|string|string[]} value a string, or an array of strings
|
|
192
|
+
* @returns {me.BitmapText} this object for chaining
|
|
192
193
|
*/
|
|
193
194
|
setText(value) {
|
|
194
195
|
if (typeof value === "undefined") {
|
|
@@ -215,16 +216,9 @@ class BitmapText extends Renderable {
|
|
|
215
216
|
* @see me.Renderable#tint
|
|
216
217
|
* @memberOf me.BitmapText
|
|
217
218
|
*/
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @ignore
|
|
221
|
-
*/
|
|
222
219
|
get fillStyle() {
|
|
223
220
|
return this.tint;
|
|
224
221
|
}
|
|
225
|
-
/**
|
|
226
|
-
* @ignore
|
|
227
|
-
*/
|
|
228
222
|
set fillStyle(value) {
|
|
229
223
|
this.tint = value;
|
|
230
224
|
}
|
|
@@ -234,8 +228,8 @@ class BitmapText extends Renderable {
|
|
|
234
228
|
* @name resize
|
|
235
229
|
* @memberOf me.BitmapText.prototype
|
|
236
230
|
* @function
|
|
237
|
-
* @param {
|
|
238
|
-
* @
|
|
231
|
+
* @param {number} scale ratio
|
|
232
|
+
* @returns {me.BitmapText} this object for chaining
|
|
239
233
|
*/
|
|
240
234
|
resize(scale) {
|
|
241
235
|
this.fontScale.set(scale, scale);
|
|
@@ -250,7 +244,7 @@ class BitmapText extends Renderable {
|
|
|
250
244
|
* @name measureText
|
|
251
245
|
* @memberOf me.BitmapText.prototype
|
|
252
246
|
* @function
|
|
253
|
-
* @param {
|
|
247
|
+
* @param {string} [text]
|
|
254
248
|
* @param {me.Rect} [ret] a object in which to store the text metrics
|
|
255
249
|
* @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
|
|
256
250
|
*/
|
|
@@ -286,9 +280,9 @@ class BitmapText extends Renderable {
|
|
|
286
280
|
* @memberOf me.BitmapText.prototype
|
|
287
281
|
* @function
|
|
288
282
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer Reference to the destination renderer instance
|
|
289
|
-
* @param {
|
|
290
|
-
* @param {
|
|
291
|
-
* @param {
|
|
283
|
+
* @param {string} [text]
|
|
284
|
+
* @param {number} [x]
|
|
285
|
+
* @param {number} [y]
|
|
292
286
|
*/
|
|
293
287
|
draw(renderer, text, x, y) {
|
|
294
288
|
// save the previous global alpha value
|
|
@@ -5,7 +5,7 @@ var capChars = ["M", "N", "B", "D", "C", "E", "F", "K", "A", "G", "H", "I", "J",
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Gets the value from a string of pairs.
|
|
8
|
-
* @
|
|
8
|
+
* @ignore
|
|
9
9
|
*/
|
|
10
10
|
function getValueFromPair(string, pattern) {
|
|
11
11
|
var value = string.match(pattern);
|
|
@@ -18,11 +18,11 @@ function getValueFromPair(string, pattern) {
|
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Gets the first glyph in the map that is not a space character
|
|
21
|
-
* @
|
|
21
|
+
* @ignore
|
|
22
22
|
* @name _getFirstGlyph
|
|
23
23
|
* @memberOf me.BitmapTextData
|
|
24
24
|
* @function
|
|
25
|
-
* @param {
|
|
25
|
+
* @param {object} glyphs the map of glyphs, each key is a char code
|
|
26
26
|
* @returns {me.Glyph}
|
|
27
27
|
*/
|
|
28
28
|
function getFirstGlyph(glyphs) {
|
|
@@ -37,11 +37,11 @@ function getFirstGlyph(glyphs) {
|
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Creates a glyph to use for the space character
|
|
40
|
-
* @
|
|
40
|
+
* @ignore
|
|
41
41
|
* @name createSpaceGlyph
|
|
42
42
|
* @memberOf me.BitmapTextData
|
|
43
43
|
* @function
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {object} glyphs the map of glyphs, each key is a char code
|
|
45
45
|
*/
|
|
46
46
|
function createSpaceGlyph(glyphs) {
|
|
47
47
|
var spaceCharCode = " ".charCodeAt(0);
|
|
@@ -60,8 +60,8 @@ function createSpaceGlyph(glyphs) {
|
|
|
60
60
|
* Class for storing relevant data from the font file.
|
|
61
61
|
* @class me.BitmapTextData
|
|
62
62
|
* @memberOf me
|
|
63
|
-
* @
|
|
64
|
-
* @param data {
|
|
63
|
+
* @ignore
|
|
64
|
+
* @param data {string} - The bitmap font data pulled from the resource loader using me.loader.getBinary()
|
|
65
65
|
* @constructor
|
|
66
66
|
*/
|
|
67
67
|
class BitmapTextData {
|
|
@@ -88,7 +88,7 @@ class BitmapTextData {
|
|
|
88
88
|
/**
|
|
89
89
|
* The map of glyphs, each key is a char code.
|
|
90
90
|
* @name glyphs
|
|
91
|
-
* @type {
|
|
91
|
+
* @type {object}
|
|
92
92
|
* @memberOf me.BitmapTextData
|
|
93
93
|
*/
|
|
94
94
|
this.glyphs = {};
|
|
@@ -102,7 +102,7 @@ class BitmapTextData {
|
|
|
102
102
|
* @name parse
|
|
103
103
|
* @memberOf me.BitmapTextData
|
|
104
104
|
* @function
|
|
105
|
-
* @param {
|
|
105
|
+
* @param {string} fontData
|
|
106
106
|
*/
|
|
107
107
|
parse(fontData) {
|
|
108
108
|
if (!fontData) {
|
package/src/text/text.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
|
-
import
|
|
3
|
-
import { renderer } from "./../video/video.js";
|
|
2
|
+
import WebGLRenderer from "./../video/webgl/webgl_renderer.js";
|
|
3
|
+
import { renderer, createCanvas } from "./../video/video.js";
|
|
4
4
|
import * as stringUtil from "./../utils/string.js";
|
|
5
5
|
import pool from "./../system/pooling.js";
|
|
6
6
|
import Renderable from "./../renderable/renderable.js";
|
|
7
|
+
import { nextPowerOfTwo } from "./../math/math.js";
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
/*
|
|
@@ -22,7 +23,7 @@ var toPX = [12, 24, 0.75, 1];
|
|
|
22
23
|
* apply the current font style to the given context
|
|
23
24
|
* @ignore
|
|
24
25
|
*/
|
|
25
|
-
var setContextStyle = function(context, font, stroke) {
|
|
26
|
+
var setContextStyle = function(context, font, stroke = false) {
|
|
26
27
|
context.font = font.font;
|
|
27
28
|
context.fillStyle = font.fillStyle.toRGBA();
|
|
28
29
|
if (stroke === true) {
|
|
@@ -40,19 +41,20 @@ var setContextStyle = function(context, font, stroke) {
|
|
|
40
41
|
* @extends me.Renderable
|
|
41
42
|
* @memberOf me
|
|
42
43
|
* @constructor
|
|
43
|
-
* @param {
|
|
44
|
-
* @param {
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {
|
|
48
|
-
* @param {me.Color|
|
|
49
|
-
* @param {me.Color|
|
|
50
|
-
* @param {
|
|
51
|
-
* @param {
|
|
52
|
-
* @param {
|
|
53
|
-
* @param {
|
|
44
|
+
* @param {number} x position of the text object
|
|
45
|
+
* @param {number} y position of the text object
|
|
46
|
+
* @param {object} settings the text configuration
|
|
47
|
+
* @param {string} settings.font a CSS family font name
|
|
48
|
+
* @param {number|string} settings.size size, or size + suffix (px, em, pt)
|
|
49
|
+
* @param {me.Color|string} [settings.fillStyle="#000000"] a CSS color value
|
|
50
|
+
* @param {me.Color|string} [settings.strokeStyle="#000000"] a CSS color value
|
|
51
|
+
* @param {number} [settings.lineWidth=1] line width, in pixels, when drawing stroke
|
|
52
|
+
* @param {string} [settings.textAlign="left"] horizontal text alignment
|
|
53
|
+
* @param {string} [settings.textBaseline="top"] the text baseline
|
|
54
|
+
* @param {number} [settings.lineHeight=1.0] line spacing height
|
|
54
55
|
* @param {me.Vector2d} [settings.anchorPoint={x:0.0, y:0.0}] anchor point to draw the text at
|
|
55
|
-
* @param {
|
|
56
|
+
* @param {boolean} [settings.offScreenCanvas=false] whether to draw the font to an individual "cache" texture first
|
|
57
|
+
* @param {(string|string[])} [settings.text=""] a string, or an array of strings
|
|
56
58
|
* @example
|
|
57
59
|
* var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
58
60
|
*/
|
|
@@ -71,7 +73,7 @@ class Text extends Renderable {
|
|
|
71
73
|
/**
|
|
72
74
|
* defines the color used to draw the font.<br>
|
|
73
75
|
* @public
|
|
74
|
-
* @type me.Color
|
|
76
|
+
* @type {me.Color}
|
|
75
77
|
* @default black
|
|
76
78
|
* @name me.Text#fillStyle
|
|
77
79
|
*/
|
|
@@ -89,7 +91,7 @@ class Text extends Renderable {
|
|
|
89
91
|
/**
|
|
90
92
|
* defines the color used to draw the font stroke.<br>
|
|
91
93
|
* @public
|
|
92
|
-
* @type me.Color
|
|
94
|
+
* @type {me.Color}
|
|
93
95
|
* @default black
|
|
94
96
|
* @name me.Text#strokeStyle
|
|
95
97
|
*/
|
|
@@ -107,7 +109,7 @@ class Text extends Renderable {
|
|
|
107
109
|
/**
|
|
108
110
|
* sets the current line width, in pixels, when drawing stroke
|
|
109
111
|
* @public
|
|
110
|
-
* @type
|
|
112
|
+
* @type {number}
|
|
111
113
|
* @default 1
|
|
112
114
|
* @name me.Text#lineWidth
|
|
113
115
|
*/
|
|
@@ -117,7 +119,7 @@ class Text extends Renderable {
|
|
|
117
119
|
* Set the default text alignment (or justification),<br>
|
|
118
120
|
* possible values are "left", "right", and "center".<br>
|
|
119
121
|
* @public
|
|
120
|
-
* @type
|
|
122
|
+
* @type {string}
|
|
121
123
|
* @default "left"
|
|
122
124
|
* @name me.Text#textAlign
|
|
123
125
|
*/
|
|
@@ -127,7 +129,7 @@ class Text extends Renderable {
|
|
|
127
129
|
* Set the text baseline (e.g. the Y-coordinate for the draw operation), <br>
|
|
128
130
|
* possible values are "top", "hanging, "middle, "alphabetic, "ideographic, "bottom"<br>
|
|
129
131
|
* @public
|
|
130
|
-
* @type
|
|
132
|
+
* @type {string}
|
|
131
133
|
* @default "top"
|
|
132
134
|
* @name me.Text#textBaseline
|
|
133
135
|
*/
|
|
@@ -137,16 +139,27 @@ class Text extends Renderable {
|
|
|
137
139
|
* Set the line spacing height (when displaying multi-line strings). <br>
|
|
138
140
|
* Current font height will be multiplied with this value to set the line height.
|
|
139
141
|
* @public
|
|
140
|
-
* @type
|
|
142
|
+
* @type {number}
|
|
141
143
|
* @default 1.0
|
|
142
144
|
* @name me.Text#lineHeight
|
|
143
145
|
*/
|
|
144
146
|
this.lineHeight = settings.lineHeight || 1.0;
|
|
145
147
|
|
|
148
|
+
/**
|
|
149
|
+
* whether to draw the font to a indidividual offscreen canvas texture first <br>
|
|
150
|
+
* Note: this will improve performances when using WebGL, but will impact
|
|
151
|
+
* memory consumption as every text element will have its own canvas texture
|
|
152
|
+
* @public
|
|
153
|
+
* @type {boolean}
|
|
154
|
+
* @default false
|
|
155
|
+
* @name me.Text#offScreenCanvas
|
|
156
|
+
*/
|
|
157
|
+
this.offScreenCanvas = false;
|
|
158
|
+
|
|
146
159
|
/**
|
|
147
160
|
* the text to be displayed
|
|
148
161
|
* @private
|
|
149
|
-
* @type {
|
|
162
|
+
* @type {string[]}
|
|
150
163
|
* @name _text
|
|
151
164
|
* @memberOf me.Text
|
|
152
165
|
*/
|
|
@@ -155,11 +168,11 @@ class Text extends Renderable {
|
|
|
155
168
|
/**
|
|
156
169
|
* the font size (in px)
|
|
157
170
|
* @public
|
|
158
|
-
* @type {
|
|
171
|
+
* @type {number}
|
|
159
172
|
* @name fontSize
|
|
160
173
|
* @default 10
|
|
161
174
|
* @memberOf me.Text
|
|
162
|
-
|
|
175
|
+
*/
|
|
163
176
|
this.fontSize = 10;
|
|
164
177
|
|
|
165
178
|
// anchor point
|
|
@@ -185,8 +198,31 @@ class Text extends Renderable {
|
|
|
185
198
|
this.italic();
|
|
186
199
|
}
|
|
187
200
|
|
|
201
|
+
if (settings.offScreenCanvas === true) {
|
|
202
|
+
this.offScreenCanvas = true;
|
|
203
|
+
this.canvas = createCanvas(2, 2, true);
|
|
204
|
+
this.context = this.canvas.getContext("2d");
|
|
205
|
+
}
|
|
206
|
+
|
|
188
207
|
// set the text
|
|
189
208
|
this.setText(settings.text);
|
|
209
|
+
|
|
210
|
+
// force update bounds on object creation
|
|
211
|
+
this.update(0);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** @ignore */
|
|
215
|
+
onDeactivateEvent() {
|
|
216
|
+
// free the canvas and potential corresponding texture when deactivated
|
|
217
|
+
if (this.offScreenCanvas === true) {
|
|
218
|
+
if (renderer instanceof WebGLRenderer) {
|
|
219
|
+
renderer.currentCompositor.unbindTexture2D(renderer.cache.get(this.canvas));
|
|
220
|
+
renderer.cache.remove(this.canvas);
|
|
221
|
+
}
|
|
222
|
+
this.canvas.width = this.canvas.height = 0;
|
|
223
|
+
this.context = undefined;
|
|
224
|
+
this.canvas = undefined;
|
|
225
|
+
}
|
|
190
226
|
}
|
|
191
227
|
|
|
192
228
|
/**
|
|
@@ -194,7 +230,7 @@ class Text extends Renderable {
|
|
|
194
230
|
* @name bold
|
|
195
231
|
* @memberOf me.Text.prototype
|
|
196
232
|
* @function
|
|
197
|
-
* @
|
|
233
|
+
* @returns {me.Text} this object for chaining
|
|
198
234
|
*/
|
|
199
235
|
bold() {
|
|
200
236
|
this.font = "bold " + this.font;
|
|
@@ -207,7 +243,7 @@ class Text extends Renderable {
|
|
|
207
243
|
* @name italic
|
|
208
244
|
* @memberOf me.Text.prototype
|
|
209
245
|
* @function
|
|
210
|
-
* @
|
|
246
|
+
* @returns {me.Text} this object for chaining
|
|
211
247
|
*/
|
|
212
248
|
italic() {
|
|
213
249
|
this.font = "italic " + this.font;
|
|
@@ -220,9 +256,9 @@ class Text extends Renderable {
|
|
|
220
256
|
* @name setFont
|
|
221
257
|
* @memberOf me.Text.prototype
|
|
222
258
|
* @function
|
|
223
|
-
* @param {
|
|
224
|
-
* @param {
|
|
225
|
-
* @
|
|
259
|
+
* @param {string} font a CSS font name
|
|
260
|
+
* @param {number|string} [size=10] size in px, or size + suffix (px, em, pt)
|
|
261
|
+
* @returns {me.Text} this object for chaining
|
|
226
262
|
* @example
|
|
227
263
|
* font.setFont("Arial", 20);
|
|
228
264
|
* font.setFont("Arial", "1.5em");
|
|
@@ -264,14 +300,10 @@ class Text extends Renderable {
|
|
|
264
300
|
* @name setText
|
|
265
301
|
* @memberOf me.Text.prototype
|
|
266
302
|
* @function
|
|
267
|
-
* @param {
|
|
268
|
-
* @
|
|
303
|
+
* @param {number|string|string[]} value a string, or an array of strings
|
|
304
|
+
* @returns {me.Text} this object for chaining
|
|
269
305
|
*/
|
|
270
|
-
setText(value) {
|
|
271
|
-
if (typeof value === "undefined") {
|
|
272
|
-
value = "";
|
|
273
|
-
}
|
|
274
|
-
|
|
306
|
+
setText(value = "") {
|
|
275
307
|
if (this._text.toString() !== value.toString()) {
|
|
276
308
|
if (!Array.isArray(value)) {
|
|
277
309
|
this._text = ("" + value).split("\n");
|
|
@@ -289,28 +321,23 @@ class Text extends Renderable {
|
|
|
289
321
|
* @name measureText
|
|
290
322
|
* @memberOf me.Text.prototype
|
|
291
323
|
* @function
|
|
292
|
-
* @param {me.CanvasRenderer|me.WebGLRenderer} [renderer] reference
|
|
293
|
-
* @param {
|
|
324
|
+
* @param {me.CanvasRenderer|me.WebGLRenderer} [renderer] reference to the active renderer
|
|
325
|
+
* @param {string} [text] the text to be measured
|
|
294
326
|
* @param {me.Rect|me.Bounds} [ret] a object in which to store the text metrics
|
|
295
327
|
* @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
|
|
296
328
|
*/
|
|
297
|
-
measureText(
|
|
329
|
+
measureText(renderer, text, ret) {
|
|
298
330
|
var context;
|
|
299
|
-
|
|
300
|
-
if (typeof _renderer === "undefined") {
|
|
301
|
-
context = renderer.getFontContext();
|
|
302
|
-
} else if (_renderer instanceof Renderer) {
|
|
303
|
-
context = _renderer.getFontContext();
|
|
304
|
-
} else {
|
|
305
|
-
// else it's a 2d rendering context object
|
|
306
|
-
context = _renderer;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
331
|
var textMetrics = ret || this.getBounds();
|
|
310
332
|
var lineHeight = this.fontSize * this.lineHeight;
|
|
311
|
-
|
|
312
333
|
var strings = typeof text !== "undefined" ? ("" + (text)).split("\n") : this._text;
|
|
313
334
|
|
|
335
|
+
if (this.offScreenCanvas === true) {
|
|
336
|
+
context = this.context;
|
|
337
|
+
} else {
|
|
338
|
+
context = renderer.getFontContext();
|
|
339
|
+
}
|
|
340
|
+
|
|
314
341
|
// save the previous context
|
|
315
342
|
context.save();
|
|
316
343
|
|
|
@@ -346,7 +373,33 @@ class Text extends Renderable {
|
|
|
346
373
|
*/
|
|
347
374
|
update(/* dt */) {
|
|
348
375
|
if (this.isDirty === true) {
|
|
349
|
-
this.measureText();
|
|
376
|
+
var bounds = this.measureText(renderer);
|
|
377
|
+
if (this.offScreenCanvas === true) {
|
|
378
|
+
var width = Math.round(bounds.width),
|
|
379
|
+
height = Math.round(bounds.height);
|
|
380
|
+
|
|
381
|
+
if (renderer instanceof WebGLRenderer) {
|
|
382
|
+
// invalidate the previous corresponding texture so that it can reuploaded once changed
|
|
383
|
+
renderer.currentCompositor.unbindTexture2D(renderer.cache.get(this.canvas));
|
|
384
|
+
|
|
385
|
+
if (renderer.WebGLVersion === 1) {
|
|
386
|
+
// round size to next Pow2
|
|
387
|
+
width = nextPowerOfTwo(bounds.width);
|
|
388
|
+
height = nextPowerOfTwo(bounds.height);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// resize the cache canvas if necessary
|
|
393
|
+
if (this.canvas.width < width || this.canvas.height < height) {
|
|
394
|
+
this.canvas.width = width;
|
|
395
|
+
this.canvas.height = height;
|
|
396
|
+
// resizing the canvas will automatically clear its content
|
|
397
|
+
} else {
|
|
398
|
+
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
399
|
+
}
|
|
400
|
+
this._drawFont(this.context, this._text, this.pos.x - bounds.x, this.pos.y - bounds.y, false);
|
|
401
|
+
|
|
402
|
+
}
|
|
350
403
|
}
|
|
351
404
|
return this.isDirty;
|
|
352
405
|
}
|
|
@@ -357,9 +410,10 @@ class Text extends Renderable {
|
|
|
357
410
|
* @memberOf me.Text.prototype
|
|
358
411
|
* @function
|
|
359
412
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer Reference to the destination renderer instance
|
|
360
|
-
* @param {
|
|
361
|
-
* @param {
|
|
362
|
-
* @param {
|
|
413
|
+
* @param {string} [text]
|
|
414
|
+
* @param {number} [x]
|
|
415
|
+
* @param {number} [y]
|
|
416
|
+
* @param {boolean} [stroke=false] draw stroke the the text if true
|
|
363
417
|
*/
|
|
364
418
|
draw(renderer, text, x, y, stroke) {
|
|
365
419
|
// "hacky patch" for backward compatibilty
|
|
@@ -396,7 +450,12 @@ class Text extends Renderable {
|
|
|
396
450
|
}
|
|
397
451
|
|
|
398
452
|
// draw the text
|
|
399
|
-
|
|
453
|
+
if (this.offScreenCanvas === true) {
|
|
454
|
+
renderer.drawImage(this.canvas, this.getBounds().x, this.getBounds().y);
|
|
455
|
+
} else {
|
|
456
|
+
renderer.drawFont(this._drawFont(renderer.getFontContext(), this._text, x, y, stroke));
|
|
457
|
+
}
|
|
458
|
+
|
|
400
459
|
|
|
401
460
|
// for backward compatibilty
|
|
402
461
|
if (typeof this.ancestor === "undefined") {
|
|
@@ -417,9 +476,9 @@ class Text extends Renderable {
|
|
|
417
476
|
* @memberOf me.Text.prototype
|
|
418
477
|
* @function
|
|
419
478
|
* @param {me.CanvasRenderer|me.WebGLRenderer} renderer Reference to the destination renderer instance
|
|
420
|
-
* @param {
|
|
421
|
-
* @param {
|
|
422
|
-
* @param {
|
|
479
|
+
* @param {string} text
|
|
480
|
+
* @param {number} x
|
|
481
|
+
* @param {number} y
|
|
423
482
|
*/
|
|
424
483
|
drawStroke(renderer, text, x, y) {
|
|
425
484
|
this.draw(renderer, text, x, y, true);
|
|
@@ -428,7 +487,7 @@ class Text extends Renderable {
|
|
|
428
487
|
/**
|
|
429
488
|
* @ignore
|
|
430
489
|
*/
|
|
431
|
-
_drawFont(context, text, x, y, stroke) {
|
|
490
|
+
_drawFont(context, text, x, y, stroke = false) {
|
|
432
491
|
setContextStyle(context, this, stroke);
|
|
433
492
|
|
|
434
493
|
var lineHeight = this.fontSize * this.lineHeight;
|
package/src/tweens/easing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tween.js - Licensed under the MIT license
|
|
3
|
-
* https://github.com/tweenjs/tween.js
|
|
4
|
-
*/
|
|
2
|
+
* Tween.js - Licensed under the MIT license
|
|
3
|
+
* https://github.com/tweenjs/tween.js
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
/* eslint-disable quotes, keyword-spacing, comma-spacing, no-return-assign */
|
|
7
7
|
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
* </p>
|
|
43
43
|
* @public
|
|
44
44
|
* @constant
|
|
45
|
-
* @
|
|
45
|
+
* @enum {Function}
|
|
46
46
|
* @name Easing
|
|
47
47
|
* @memberOf me.Tween
|
|
48
48
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tween.js - Licensed under the MIT license
|
|
3
|
-
* https://github.com/tweenjs/tween.js
|
|
4
|
-
*/
|
|
2
|
+
* Tween.js - Licensed under the MIT license
|
|
3
|
+
* https://github.com/tweenjs/tween.js
|
|
4
|
+
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Interpolation Function :<br>
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* </p>
|
|
13
13
|
* @public
|
|
14
14
|
* @constant
|
|
15
|
-
* @
|
|
15
|
+
* @enum {Function}
|
|
16
16
|
* @name Interpolation
|
|
17
17
|
* @memberOf me.Tween
|
|
18
18
|
*/
|