melonjs 10.5.2 → 10.7.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/README.md +4 -6
- package/dist/melonjs.js +37470 -36394
- package/dist/melonjs.min.js +22 -22
- package/dist/melonjs.module.d.ts +606 -426
- package/dist/melonjs.module.js +8114 -7033
- package/package.json +15 -13
- package/src/camera/camera2d.js +11 -10
- package/src/game.js +5 -5
- package/src/geometries/ellipse.js +1 -1
- package/src/geometries/poly.js +1 -1
- package/src/geometries/rectangle.js +15 -0
- package/src/index.js +5 -5
- package/src/input/gamepad.js +12 -10
- package/src/input/keyboard.js +5 -3
- package/src/input/pointer.js +1 -1
- package/src/input/pointerevent.js +3 -4
- package/src/level/tiled/TMXLayer.js +1 -1
- package/src/level/tiled/TMXTileMap.js +1 -1
- package/src/level/tiled/TMXUtils.js +1 -1
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -1
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -1
- package/src/loader/loader.js +1 -1
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +1 -1
- package/src/math/matrix2.js +2 -2
- package/src/math/matrix3.js +67 -66
- package/src/math/observable_vector2.js +1 -1
- package/src/math/observable_vector3.js +1 -1
- package/src/math/vector2.js +1 -1
- package/src/math/vector3.js +1 -1
- package/src/particles/emitter.js +120 -429
- package/src/particles/particle.js +51 -52
- package/src/particles/settings.js +310 -0
- package/src/physics/body.js +7 -7
- package/src/polyfill/console.js +7 -7
- package/src/polyfill/index.js +7 -0
- package/src/polyfill/performance.js +20 -0
- package/src/polyfill/requestAnimationFrame.js +10 -10
- package/src/renderable/colorlayer.js +1 -1
- package/src/renderable/container.js +11 -1
- package/src/renderable/imagelayer.js +3 -3
- package/src/renderable/nineslicesprite.js +6 -3
- package/src/renderable/renderable.js +18 -1
- package/src/renderable/sprite.js +2 -2
- package/src/state/state.js +13 -13
- package/src/system/device.js +141 -128
- package/src/system/event.js +10 -10
- package/src/system/pooling.js +150 -155
- package/src/system/timer.js +1 -1
- package/src/text/bitmaptext.js +35 -91
- package/src/text/text.js +82 -145
- package/src/text/textmetrics.js +168 -0
- package/src/text/textstyle.js +14 -0
- package/src/utils/agent.js +4 -4
- package/src/utils/function.js +2 -2
- package/src/utils/utils.js +10 -5
- package/src/video/canvas/canvas_renderer.js +34 -4
- package/src/video/renderer.js +3 -5
- package/src/video/texture.js +1 -1
- package/src/video/video.js +11 -11
- package/src/video/webgl/buffer/vertex.js +0 -3
- package/src/video/webgl/glshader.js +1 -3
- package/src/video/webgl/webgl_renderer.js +50 -22
- package/src/particles/particlecontainer.js +0 -95
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { renderer } from "./../video/video.js";
|
|
2
2
|
import * as event from "./../system/event.js";
|
|
3
|
-
import pool from "./../system/pooling.js";
|
|
3
|
+
import * as pool from "./../system/pooling.js";
|
|
4
4
|
import { viewport } from "./../game.js";
|
|
5
5
|
import Sprite from "./sprite.js";
|
|
6
6
|
import * as stringUtil from "./../utils/string.js";
|
|
@@ -93,7 +93,7 @@ class ImageLayer extends Sprite {
|
|
|
93
93
|
this.repeat = settings.repeat || "repeat";
|
|
94
94
|
|
|
95
95
|
// on context lost, all previous textures are destroyed
|
|
96
|
-
event.on(event.
|
|
96
|
+
event.on(event.ONCONTEXT_RESTORED, this.createPattern, this);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/**
|
|
@@ -294,7 +294,7 @@ class ImageLayer extends Sprite {
|
|
|
294
294
|
destroy() {
|
|
295
295
|
pool.push(this.ratio);
|
|
296
296
|
this.ratio = undefined;
|
|
297
|
-
event.off(event.
|
|
297
|
+
event.off(event.ONCONTEXT_RESTORED, this.createPattern);
|
|
298
298
|
super.destroy();
|
|
299
299
|
}
|
|
300
300
|
|
|
@@ -43,13 +43,16 @@ class NineSliceSprite extends Sprite {
|
|
|
43
43
|
throw new Error("height and width properties are mandatory");
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
// adjust the nss sprite size accordingly to the target "expanded" size
|
|
47
|
+
this.width = Math.floor(settings.width);
|
|
48
|
+
this.height = Math.floor(settings.height);
|
|
49
|
+
|
|
46
50
|
// nine slice sprite specific local variables
|
|
47
|
-
this.nss_width =
|
|
48
|
-
this.nss_height =
|
|
51
|
+
this.nss_width = this.width;
|
|
52
|
+
this.nss_height = this.height;
|
|
49
53
|
|
|
50
54
|
this.insetx = settings.insetx;
|
|
51
55
|
this.insety = settings.insety;
|
|
52
|
-
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/**
|
|
@@ -2,7 +2,7 @@ import ObservableVector2d from "./../math/observable_vector2.js";
|
|
|
2
2
|
import ObservableVector3d from "./../math/observable_vector3.js";
|
|
3
3
|
import Rect from "./../geometries/rectangle.js";
|
|
4
4
|
import Container from "./container.js";
|
|
5
|
-
import pool from "./../system/pooling.js";
|
|
5
|
+
import * as pool from "./../system/pooling.js";
|
|
6
6
|
import { releaseAllPointerEvents } from "./../input/input.js";
|
|
7
7
|
import { clamp } from "./../math/math.js";
|
|
8
8
|
|
|
@@ -264,6 +264,18 @@ class Renderable extends Rect {
|
|
|
264
264
|
*/
|
|
265
265
|
this.tint = pool.pull("Color", 255, 255, 255, 1.0);
|
|
266
266
|
|
|
267
|
+
/**
|
|
268
|
+
* the blend mode to be applied to this renderable (see renderer setBlendMode for available blend mode)
|
|
269
|
+
* @public
|
|
270
|
+
* @type {string}
|
|
271
|
+
* @name blendMode
|
|
272
|
+
* @default "normal"
|
|
273
|
+
* @see CanvasRenderer#setBlendMode
|
|
274
|
+
* @see WebGLRenderer#setBlendMode
|
|
275
|
+
* @memberof Renderable#
|
|
276
|
+
*/
|
|
277
|
+
this.blendMode = "normal";
|
|
278
|
+
|
|
267
279
|
/**
|
|
268
280
|
* The name of the renderable
|
|
269
281
|
* @public
|
|
@@ -732,6 +744,11 @@ class Renderable extends Rect {
|
|
|
732
744
|
|
|
733
745
|
// apply the current tint and opacity
|
|
734
746
|
renderer.setTint(this.tint, this.getOpacity());
|
|
747
|
+
|
|
748
|
+
// apply blending if different from "normal"
|
|
749
|
+
if (this.blendMode !== renderer.getBlendMode()) {
|
|
750
|
+
renderer.setBlendMode(this.blendMode);
|
|
751
|
+
}
|
|
735
752
|
}
|
|
736
753
|
|
|
737
754
|
/**
|
package/src/renderable/sprite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Vector2d from "./../math/vector2.js";
|
|
2
2
|
import { renderer } from "./../video/video.js";
|
|
3
|
-
import pool from "./../system/pooling.js";
|
|
3
|
+
import * as pool from "./../system/pooling.js";
|
|
4
4
|
import loader from "./../loader/loader.js";
|
|
5
5
|
import { TextureAtlas } from "./../video/texture.js";
|
|
6
6
|
import Renderable from "./renderable.js";
|
|
@@ -584,7 +584,7 @@ class Sprite extends Renderable {
|
|
|
584
584
|
this.isDirty = true;
|
|
585
585
|
}
|
|
586
586
|
|
|
587
|
-
return
|
|
587
|
+
return super.update(dt);
|
|
588
588
|
}
|
|
589
589
|
|
|
590
590
|
/**
|
package/src/state/state.js
CHANGED
|
@@ -45,7 +45,7 @@ function _startRunLoop() {
|
|
|
45
45
|
timer.reset();
|
|
46
46
|
|
|
47
47
|
// start the main loop
|
|
48
|
-
_animFrameId =
|
|
48
|
+
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -64,7 +64,7 @@ function _resumeRunLoop() {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
|
-
* Pause the loop for most
|
|
67
|
+
* Pause the loop for most stage objects.
|
|
68
68
|
* @ignore
|
|
69
69
|
*/
|
|
70
70
|
function _pauseRunLoop() {
|
|
@@ -85,7 +85,7 @@ function _renderFrame(time) {
|
|
|
85
85
|
game.draw(stage);
|
|
86
86
|
// schedule the next frame update
|
|
87
87
|
if (_animFrameId !== -1) {
|
|
88
|
-
_animFrameId =
|
|
88
|
+
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -95,7 +95,7 @@ function _renderFrame(time) {
|
|
|
95
95
|
*/
|
|
96
96
|
function _stopRunLoop() {
|
|
97
97
|
// cancel any previous animationRequestFrame
|
|
98
|
-
|
|
98
|
+
globalThis.cancelAnimationFrame(_animFrameId);
|
|
99
99
|
_animFrameId = -1;
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -249,7 +249,7 @@ var state = {
|
|
|
249
249
|
USER : 100,
|
|
250
250
|
|
|
251
251
|
/**
|
|
252
|
-
* Stop the current
|
|
252
|
+
* Stop the current stage.
|
|
253
253
|
* @name stop
|
|
254
254
|
* @memberof state
|
|
255
255
|
* @public
|
|
@@ -268,7 +268,7 @@ var state = {
|
|
|
268
268
|
}
|
|
269
269
|
|
|
270
270
|
// store time when stopped
|
|
271
|
-
_pauseTime =
|
|
271
|
+
_pauseTime = globalThis.performance.now();
|
|
272
272
|
|
|
273
273
|
// publish the stop notification
|
|
274
274
|
event.emit(event.STATE_STOP);
|
|
@@ -276,7 +276,7 @@ var state = {
|
|
|
276
276
|
},
|
|
277
277
|
|
|
278
278
|
/**
|
|
279
|
-
* pause the current
|
|
279
|
+
* pause the current stage
|
|
280
280
|
* @name pause
|
|
281
281
|
* @memberof state
|
|
282
282
|
* @public
|
|
@@ -294,7 +294,7 @@ var state = {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
// store time when paused
|
|
297
|
-
_pauseTime =
|
|
297
|
+
_pauseTime = globalThis.performance.now();
|
|
298
298
|
|
|
299
299
|
// publish the pause event
|
|
300
300
|
event.emit(event.STATE_PAUSE);
|
|
@@ -302,7 +302,7 @@ var state = {
|
|
|
302
302
|
},
|
|
303
303
|
|
|
304
304
|
/**
|
|
305
|
-
* Restart the
|
|
305
|
+
* Restart the current stage from a full stop.
|
|
306
306
|
* @name restart
|
|
307
307
|
* @memberof state
|
|
308
308
|
* @public
|
|
@@ -319,7 +319,7 @@ var state = {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
// calculate the elpased time
|
|
322
|
-
_pauseTime =
|
|
322
|
+
_pauseTime = globalThis.performance.now() - _pauseTime;
|
|
323
323
|
|
|
324
324
|
// force repaint
|
|
325
325
|
game.repaint();
|
|
@@ -330,7 +330,7 @@ var state = {
|
|
|
330
330
|
},
|
|
331
331
|
|
|
332
332
|
/**
|
|
333
|
-
* resume the
|
|
333
|
+
* resume the current stage
|
|
334
334
|
* @name resume
|
|
335
335
|
* @memberof state
|
|
336
336
|
* @public
|
|
@@ -347,7 +347,7 @@ var state = {
|
|
|
347
347
|
}
|
|
348
348
|
|
|
349
349
|
// calculate the elpased time
|
|
350
|
-
_pauseTime =
|
|
350
|
+
_pauseTime = globalThis.performance.now() - _pauseTime;
|
|
351
351
|
|
|
352
352
|
// publish the resume event
|
|
353
353
|
event.emit(event.STATE_RESUME, _pauseTime);
|
|
@@ -438,7 +438,7 @@ var state = {
|
|
|
438
438
|
},
|
|
439
439
|
|
|
440
440
|
/**
|
|
441
|
-
* return a reference to the current
|
|
441
|
+
* return a reference to the current stage<br>
|
|
442
442
|
* useful to call a object specific method
|
|
443
443
|
* @name current
|
|
444
444
|
* @memberof state
|