melonjs 9.1.0 → 10.0.1
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 → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
package/src/text/text.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Color from "./../math/color.js";
|
|
2
2
|
import Renderer from "./../video/renderer.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import { renderer } from "./../video/video.js";
|
|
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
7
|
|
|
@@ -55,12 +55,17 @@ var setContextStyle = function(context, font, stroke) {
|
|
|
55
55
|
* @example
|
|
56
56
|
* var font = new me.Text(0, 0, {font: "Arial", size: 8, fillStyle: this.color});
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
class Text extends Renderable {
|
|
59
59
|
|
|
60
60
|
/** @ignore */
|
|
61
|
-
|
|
61
|
+
constructor(x, y, settings) {
|
|
62
62
|
// call the parent constructor
|
|
63
|
-
|
|
63
|
+
super(x, y, settings.width || 0, settings.height || 0);
|
|
64
|
+
this.onResetEvent(x, y, settings);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @ignore */
|
|
68
|
+
onResetEvent(x, y, settings) {
|
|
64
69
|
|
|
65
70
|
/**
|
|
66
71
|
* defines the color used to draw the font.<br>
|
|
@@ -181,7 +186,7 @@ var Text = Renderable.extend({
|
|
|
181
186
|
|
|
182
187
|
// set the text
|
|
183
188
|
this.setText(settings.text);
|
|
184
|
-
}
|
|
189
|
+
}
|
|
185
190
|
|
|
186
191
|
/**
|
|
187
192
|
* make the font bold
|
|
@@ -190,11 +195,11 @@ var Text = Renderable.extend({
|
|
|
190
195
|
* @function
|
|
191
196
|
* @return this object for chaining
|
|
192
197
|
*/
|
|
193
|
-
bold
|
|
198
|
+
bold() {
|
|
194
199
|
this.font = "bold " + this.font;
|
|
195
200
|
this.isDirty = true;
|
|
196
201
|
return this;
|
|
197
|
-
}
|
|
202
|
+
}
|
|
198
203
|
|
|
199
204
|
/**
|
|
200
205
|
* make the font italic
|
|
@@ -203,11 +208,11 @@ var Text = Renderable.extend({
|
|
|
203
208
|
* @function
|
|
204
209
|
* @return this object for chaining
|
|
205
210
|
*/
|
|
206
|
-
italic
|
|
211
|
+
italic() {
|
|
207
212
|
this.font = "italic " + this.font;
|
|
208
213
|
this.isDirty = true;
|
|
209
214
|
return this;
|
|
210
|
-
}
|
|
215
|
+
}
|
|
211
216
|
|
|
212
217
|
/**
|
|
213
218
|
* set the font family and size
|
|
@@ -221,7 +226,7 @@ var Text = Renderable.extend({
|
|
|
221
226
|
* font.setFont("Arial", 20);
|
|
222
227
|
* font.setFont("Arial", "1.5em");
|
|
223
228
|
*/
|
|
224
|
-
setFont
|
|
229
|
+
setFont(font, size) {
|
|
225
230
|
// font name and type
|
|
226
231
|
var font_names = font.split(",").map(function (value) {
|
|
227
232
|
value = value.trim();
|
|
@@ -251,7 +256,7 @@ var Text = Renderable.extend({
|
|
|
251
256
|
this.isDirty = true;
|
|
252
257
|
|
|
253
258
|
return this;
|
|
254
|
-
}
|
|
259
|
+
}
|
|
255
260
|
|
|
256
261
|
/**
|
|
257
262
|
* change the text to be displayed
|
|
@@ -261,7 +266,7 @@ var Text = Renderable.extend({
|
|
|
261
266
|
* @param {Number|String|String[]} value a string, or an array of strings
|
|
262
267
|
* @return this object for chaining
|
|
263
268
|
*/
|
|
264
|
-
setText
|
|
269
|
+
setText(value) {
|
|
265
270
|
if (typeof value === "undefined") {
|
|
266
271
|
value = "";
|
|
267
272
|
}
|
|
@@ -276,7 +281,7 @@ var Text = Renderable.extend({
|
|
|
276
281
|
}
|
|
277
282
|
|
|
278
283
|
return this;
|
|
279
|
-
}
|
|
284
|
+
}
|
|
280
285
|
|
|
281
286
|
/**
|
|
282
287
|
* measure the given text size in pixels
|
|
@@ -288,16 +293,16 @@ var Text = Renderable.extend({
|
|
|
288
293
|
* @param {me.Rect|me.Bounds} [ret] a object in which to store the text metrics
|
|
289
294
|
* @returns {TextMetrics} a TextMetrics object with two properties: `width` and `height`, defining the output dimensions
|
|
290
295
|
*/
|
|
291
|
-
measureText
|
|
296
|
+
measureText(_renderer, text, ret) {
|
|
292
297
|
var context;
|
|
293
298
|
|
|
294
|
-
if (typeof
|
|
295
|
-
context = video.renderer.getFontContext();
|
|
296
|
-
} else if (renderer instanceof Renderer) {
|
|
299
|
+
if (typeof _renderer === "undefined") {
|
|
297
300
|
context = renderer.getFontContext();
|
|
301
|
+
} else if (_renderer instanceof Renderer) {
|
|
302
|
+
context = _renderer.getFontContext();
|
|
298
303
|
} else {
|
|
299
304
|
// else it's a 2d rendering context object
|
|
300
|
-
context =
|
|
305
|
+
context = _renderer;
|
|
301
306
|
}
|
|
302
307
|
|
|
303
308
|
var textMetrics = ret || this.getBounds();
|
|
@@ -314,7 +319,7 @@ var Text = Renderable.extend({
|
|
|
314
319
|
// compute the bounding box size
|
|
315
320
|
this.height = this.width = 0;
|
|
316
321
|
for (var i = 0; i < strings.length; i++) {
|
|
317
|
-
this.width = Math.max(context.measureText(
|
|
322
|
+
this.width = Math.max(context.measureText(stringUtil.trimRight(""+strings[i])).width, this.width);
|
|
318
323
|
this.height += lineHeight;
|
|
319
324
|
}
|
|
320
325
|
textMetrics.width = Math.ceil(this.width);
|
|
@@ -333,17 +338,17 @@ var Text = Renderable.extend({
|
|
|
333
338
|
|
|
334
339
|
// returns the Font bounds me.Rect by default
|
|
335
340
|
return textMetrics;
|
|
336
|
-
}
|
|
341
|
+
}
|
|
337
342
|
|
|
338
343
|
/**
|
|
339
344
|
* @ignore
|
|
340
345
|
*/
|
|
341
|
-
update
|
|
346
|
+
update(/* dt */) {
|
|
342
347
|
if (this.isDirty === true) {
|
|
343
348
|
this.measureText();
|
|
344
349
|
}
|
|
345
350
|
return this.isDirty;
|
|
346
|
-
}
|
|
351
|
+
}
|
|
347
352
|
|
|
348
353
|
/**
|
|
349
354
|
* draw a text at the specified coord
|
|
@@ -355,7 +360,7 @@ var Text = Renderable.extend({
|
|
|
355
360
|
* @param {Number} [x]
|
|
356
361
|
* @param {Number} [y]
|
|
357
362
|
*/
|
|
358
|
-
draw
|
|
363
|
+
draw(renderer, text, x, y, stroke) {
|
|
359
364
|
// "hacky patch" for backward compatibilty
|
|
360
365
|
if (typeof this.ancestor === "undefined") {
|
|
361
366
|
// update text cache
|
|
@@ -401,7 +406,7 @@ var Text = Renderable.extend({
|
|
|
401
406
|
// clear the dirty flag here for
|
|
402
407
|
// backward compatibility
|
|
403
408
|
this.isDirty = false;
|
|
404
|
-
}
|
|
409
|
+
}
|
|
405
410
|
|
|
406
411
|
/**
|
|
407
412
|
* draw a stroke text at the specified coord, as defined <br>
|
|
@@ -415,38 +420,38 @@ var Text = Renderable.extend({
|
|
|
415
420
|
* @param {Number} x
|
|
416
421
|
* @param {Number} y
|
|
417
422
|
*/
|
|
418
|
-
drawStroke
|
|
419
|
-
this.draw
|
|
420
|
-
}
|
|
423
|
+
drawStroke(renderer, text, x, y) {
|
|
424
|
+
this.draw(renderer, text, x, y, true);
|
|
425
|
+
}
|
|
421
426
|
|
|
422
427
|
/**
|
|
423
428
|
* @ignore
|
|
424
429
|
*/
|
|
425
|
-
_drawFont
|
|
430
|
+
_drawFont(context, text, x, y, stroke) {
|
|
426
431
|
setContextStyle(context, this, stroke);
|
|
427
432
|
|
|
428
433
|
var lineHeight = this.fontSize * this.lineHeight;
|
|
429
434
|
for (var i = 0; i < text.length; i++) {
|
|
430
|
-
var string =
|
|
435
|
+
var string = stringUtil.trimRight(""+text[i]);
|
|
431
436
|
// draw the string
|
|
432
437
|
context[stroke ? "strokeText" : "fillText"](string, x, y);
|
|
433
438
|
// add leading space
|
|
434
439
|
y += lineHeight;
|
|
435
440
|
}
|
|
436
441
|
return this.getBounds();
|
|
437
|
-
}
|
|
442
|
+
}
|
|
438
443
|
|
|
439
444
|
/**
|
|
440
445
|
* Destroy function
|
|
441
446
|
* @ignore
|
|
442
447
|
*/
|
|
443
|
-
destroy
|
|
448
|
+
destroy() {
|
|
444
449
|
pool.push(this.fillStyle);
|
|
445
450
|
pool.push(this.strokeStyle);
|
|
446
451
|
this.fillStyle = this.strokeStyle = undefined;
|
|
447
452
|
this._text.length = 0;
|
|
448
|
-
|
|
453
|
+
super.destroy();
|
|
449
454
|
}
|
|
450
|
-
}
|
|
455
|
+
};
|
|
451
456
|
|
|
452
457
|
export default Text;
|
package/src/tweens/easing.js
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
* https://github.com/tweenjs/tween.js
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
/* eslint-disable quotes, keyword-spacing, comma-spacing, no-return-assign */
|
|
7
|
-
|
|
8
6
|
/**
|
|
9
7
|
* Interpolation Function :<br>
|
|
10
8
|
* <p>
|
|
@@ -72,7 +70,7 @@ export let Interpolation = {
|
|
|
72
70
|
|
|
73
71
|
},
|
|
74
72
|
/** @ignore */
|
|
75
|
-
Bernstein: function ( n
|
|
73
|
+
Bernstein: function ( n, i ) {
|
|
76
74
|
|
|
77
75
|
var fc = Interpolation.Utils.Factorial;
|
|
78
76
|
return fc( n ) / fc( i ) / fc( n - i );
|
|
@@ -88,7 +86,8 @@ export let Interpolation = {
|
|
|
88
86
|
var s = 1, i;
|
|
89
87
|
if ( a[ n ] ) return a[ n ];
|
|
90
88
|
for ( i = n; i > 1; i-- ) s *= i;
|
|
91
|
-
|
|
89
|
+
a[ n ] = s;
|
|
90
|
+
return s;
|
|
92
91
|
|
|
93
92
|
};
|
|
94
93
|
|
|
@@ -98,11 +97,7 @@ export let Interpolation = {
|
|
|
98
97
|
|
|
99
98
|
var v0 = ( p2 - p0 ) * 0.5, v1 = ( p3 - p1 ) * 0.5, t2 = t * t, t3 = t * t2;
|
|
100
99
|
return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
|
|
101
|
-
|
|
102
100
|
}
|
|
103
|
-
|
|
104
101
|
}
|
|
105
102
|
|
|
106
103
|
};
|
|
107
|
-
|
|
108
|
-
/* eslint-enable quotes, keyword-spacing, comma-spacing, no-return-assign */
|