melonjs 10.2.0 → 10.3.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 +1 -1
- package/dist/melonjs.js +4435 -4283
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3348 -3833
- package/dist/melonjs.module.js +4025 -3920
- package/package.json +13 -14
- package/src/audio/audio.js +45 -45
- package/src/camera/camera2d.js +78 -101
- package/src/entity/draggable.js +21 -29
- package/src/entity/droptarget.js +24 -31
- package/src/entity/entity.js +34 -38
- package/src/game.js +8 -8
- package/src/{shapes → geometries}/ellipse.js +46 -46
- package/src/{shapes → geometries}/line.js +14 -14
- package/src/{shapes → geometries}/poly.js +103 -54
- package/src/{shapes → geometries}/rectangle.js +73 -120
- package/src/index.js +18 -19
- package/src/input/gamepad.js +20 -20
- package/src/input/input.js +3 -3
- package/src/input/keyboard.js +122 -124
- package/src/input/pointer.js +102 -62
- package/src/input/pointerevent.js +97 -42
- package/src/lang/deprecated.js +29 -18
- package/src/level/level.js +34 -26
- package/src/level/tiled/TMXGroup.js +12 -13
- package/src/level/tiled/TMXLayer.js +41 -42
- package/src/level/tiled/TMXObject.js +76 -70
- package/src/level/tiled/TMXTile.js +13 -15
- package/src/level/tiled/TMXTileMap.js +26 -25
- package/src/level/tiled/TMXTileset.js +14 -15
- package/src/level/tiled/TMXTilesetGroup.js +5 -6
- package/src/level/tiled/TMXUtils.js +13 -11
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +3 -4
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXRenderer.js +18 -19
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +2 -3
- package/src/loader/loader.js +46 -40
- package/src/loader/loadingscreen.js +7 -7
- package/src/math/color.js +68 -88
- package/src/math/math.js +33 -33
- package/src/math/matrix2.js +70 -71
- package/src/math/matrix3.js +90 -91
- package/src/math/observable_vector2.js +91 -92
- package/src/math/observable_vector3.js +110 -106
- package/src/math/vector2.js +116 -104
- package/src/math/vector3.js +129 -110
- package/src/particles/emitter.js +116 -126
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +82 -83
- package/src/physics/bounds.js +64 -66
- package/src/physics/collision.js +21 -22
- package/src/physics/detector.js +13 -13
- package/src/physics/quadtree.js +26 -25
- package/src/physics/sat.js +21 -21
- package/src/physics/world.js +23 -22
- package/src/plugin/plugin.js +12 -13
- package/src/renderable/GUI.js +20 -26
- package/src/renderable/collectable.js +6 -7
- package/src/renderable/colorlayer.js +11 -12
- package/src/renderable/container.js +98 -81
- package/src/renderable/imagelayer.js +33 -35
- package/src/renderable/nineslicesprite.js +15 -16
- package/src/renderable/renderable.js +112 -111
- package/src/renderable/sprite.js +71 -58
- package/src/renderable/trigger.js +17 -19
- package/src/state/stage.js +14 -15
- package/src/state/state.js +78 -78
- package/src/system/device.js +137 -180
- package/src/system/event.js +116 -104
- package/src/system/pooling.js +15 -15
- package/src/system/save.js +9 -6
- package/src/system/timer.js +33 -33
- package/src/text/bitmaptext.js +39 -46
- package/src/text/bitmaptextdata.js +14 -15
- package/src/text/text.js +55 -58
- package/src/tweens/easing.js +5 -5
- package/src/tweens/interpolation.js +5 -5
- package/src/tweens/tween.js +49 -40
- package/src/utils/agent.js +12 -11
- package/src/utils/array.js +8 -8
- package/src/utils/file.js +7 -7
- package/src/utils/function.js +8 -8
- package/src/utils/string.js +19 -19
- package/src/utils/utils.js +23 -23
- package/src/video/canvas/canvas_renderer.js +127 -128
- package/src/video/renderer.js +69 -69
- package/src/video/texture.js +80 -82
- package/src/video/texture_cache.js +2 -4
- package/src/video/video.js +38 -38
- package/src/video/webgl/buffer/vertex.js +11 -3
- package/src/video/webgl/glshader.js +31 -32
- package/src/video/webgl/webgl_compositor.js +145 -127
- package/src/video/webgl/webgl_renderer.js +196 -175
package/src/state/state.js
CHANGED
|
@@ -74,7 +74,7 @@ function _pauseRunLoop() {
|
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* this is only called when using requestAnimFrame stuff
|
|
77
|
-
* @param {
|
|
77
|
+
* @param {number} time current timestamp in milliseconds
|
|
78
78
|
* @ignore
|
|
79
79
|
*/
|
|
80
80
|
function _renderFrame(time) {
|
|
@@ -150,7 +150,7 @@ event.on(event.BOOT, () => {
|
|
|
150
150
|
/**
|
|
151
151
|
* a State Manager (state machine)
|
|
152
152
|
* @namespace state
|
|
153
|
-
* @
|
|
153
|
+
* @memberof me
|
|
154
154
|
*/
|
|
155
155
|
|
|
156
156
|
var state = {
|
|
@@ -159,7 +159,7 @@ var state = {
|
|
|
159
159
|
* default state ID for Loading Stage
|
|
160
160
|
* @constant
|
|
161
161
|
* @name LOADING
|
|
162
|
-
* @
|
|
162
|
+
* @memberof me.state
|
|
163
163
|
*/
|
|
164
164
|
LOADING : 0,
|
|
165
165
|
|
|
@@ -167,7 +167,7 @@ var state = {
|
|
|
167
167
|
* default state ID for Menu Stage
|
|
168
168
|
* @constant
|
|
169
169
|
* @name MENU
|
|
170
|
-
* @
|
|
170
|
+
* @memberof me.state
|
|
171
171
|
*/
|
|
172
172
|
MENU : 1,
|
|
173
173
|
|
|
@@ -175,7 +175,7 @@ var state = {
|
|
|
175
175
|
* default state ID for "Ready" Stage
|
|
176
176
|
* @constant
|
|
177
177
|
* @name READY
|
|
178
|
-
* @
|
|
178
|
+
* @memberof me.state
|
|
179
179
|
*/
|
|
180
180
|
READY : 2,
|
|
181
181
|
|
|
@@ -183,7 +183,7 @@ var state = {
|
|
|
183
183
|
* default state ID for Play Stage
|
|
184
184
|
* @constant
|
|
185
185
|
* @name PLAY
|
|
186
|
-
* @
|
|
186
|
+
* @memberof me.state
|
|
187
187
|
*/
|
|
188
188
|
PLAY : 3,
|
|
189
189
|
|
|
@@ -191,7 +191,7 @@ var state = {
|
|
|
191
191
|
* default state ID for Game Over Stage
|
|
192
192
|
* @constant
|
|
193
193
|
* @name GAMEOVER
|
|
194
|
-
* @
|
|
194
|
+
* @memberof me.state
|
|
195
195
|
*/
|
|
196
196
|
GAMEOVER : 4,
|
|
197
197
|
|
|
@@ -199,7 +199,7 @@ var state = {
|
|
|
199
199
|
* default state ID for Game End Stage
|
|
200
200
|
* @constant
|
|
201
201
|
* @name GAME_END
|
|
202
|
-
* @
|
|
202
|
+
* @memberof me.state
|
|
203
203
|
*/
|
|
204
204
|
GAME_END : 5,
|
|
205
205
|
|
|
@@ -207,7 +207,7 @@ var state = {
|
|
|
207
207
|
* default state ID for High Score Stage
|
|
208
208
|
* @constant
|
|
209
209
|
* @name SCORE
|
|
210
|
-
* @
|
|
210
|
+
* @memberof me.state
|
|
211
211
|
*/
|
|
212
212
|
SCORE : 6,
|
|
213
213
|
|
|
@@ -215,7 +215,7 @@ var state = {
|
|
|
215
215
|
* default state ID for Credits Stage
|
|
216
216
|
* @constant
|
|
217
217
|
* @name CREDITS
|
|
218
|
-
* @
|
|
218
|
+
* @memberof me.state
|
|
219
219
|
*/
|
|
220
220
|
CREDITS : 7,
|
|
221
221
|
|
|
@@ -223,7 +223,7 @@ var state = {
|
|
|
223
223
|
* default state ID for Settings Stage
|
|
224
224
|
* @constant
|
|
225
225
|
* @name SETTINGS
|
|
226
|
-
* @
|
|
226
|
+
* @memberof me.state
|
|
227
227
|
*/
|
|
228
228
|
SETTINGS : 8,
|
|
229
229
|
|
|
@@ -232,7 +232,7 @@ var state = {
|
|
|
232
232
|
* (the default stage is the one running as soon as melonJS is started)
|
|
233
233
|
* @constant
|
|
234
234
|
* @name SETTINGS
|
|
235
|
-
* @
|
|
235
|
+
* @memberof me.state
|
|
236
236
|
*/
|
|
237
237
|
DEFAULT : 9,
|
|
238
238
|
|
|
@@ -240,7 +240,7 @@ var state = {
|
|
|
240
240
|
* default state ID for user defined constants<br>
|
|
241
241
|
* @constant
|
|
242
242
|
* @name USER
|
|
243
|
-
* @
|
|
243
|
+
* @memberof me.state
|
|
244
244
|
* @example
|
|
245
245
|
* var STATE_INFO = me.state.USER + 0;
|
|
246
246
|
* var STATE_WARN = me.state.USER + 1;
|
|
@@ -252,18 +252,19 @@ var state = {
|
|
|
252
252
|
/**
|
|
253
253
|
* Stop the current screen object.
|
|
254
254
|
* @name stop
|
|
255
|
-
* @
|
|
255
|
+
* @memberof me.state
|
|
256
256
|
* @public
|
|
257
257
|
* @function
|
|
258
|
-
* @param {
|
|
258
|
+
* @param {boolean} [pauseTrack=false] pause current track on screen stop.
|
|
259
259
|
*/
|
|
260
|
-
stop(
|
|
260
|
+
stop(pauseTrack=false) {
|
|
261
261
|
// only stop when we are not loading stuff
|
|
262
262
|
if ((_state !== this.LOADING) && this.isRunning()) {
|
|
263
263
|
// stop the main loop
|
|
264
264
|
_stopRunLoop();
|
|
265
|
+
|
|
265
266
|
// current music stop
|
|
266
|
-
if (
|
|
267
|
+
if (pauseTrack === true) {
|
|
267
268
|
pauseTrack();
|
|
268
269
|
}
|
|
269
270
|
|
|
@@ -278,12 +279,12 @@ var state = {
|
|
|
278
279
|
/**
|
|
279
280
|
* pause the current screen object
|
|
280
281
|
* @name pause
|
|
281
|
-
* @
|
|
282
|
+
* @memberof me.state
|
|
282
283
|
* @public
|
|
283
284
|
* @function
|
|
284
|
-
* @param {
|
|
285
|
+
* @param {boolean} [music=false] pause current music track on screen pause
|
|
285
286
|
*/
|
|
286
|
-
pause(music) {
|
|
287
|
+
pause(music=false) {
|
|
287
288
|
// only pause when we are not loading stuff
|
|
288
289
|
if ((_state !== this.LOADING) && !this.isPaused()) {
|
|
289
290
|
// stop the main loop
|
|
@@ -304,12 +305,12 @@ var state = {
|
|
|
304
305
|
/**
|
|
305
306
|
* Restart the screen object from a full stop.
|
|
306
307
|
* @name restart
|
|
307
|
-
* @
|
|
308
|
+
* @memberof me.state
|
|
308
309
|
* @public
|
|
309
310
|
* @function
|
|
310
|
-
* @param {
|
|
311
|
+
* @param {boolean} [music=false] resume current music track on screen resume
|
|
311
312
|
*/
|
|
312
|
-
restart(music) {
|
|
313
|
+
restart(music=false) {
|
|
313
314
|
if (!this.isRunning()) {
|
|
314
315
|
// restart the main loop
|
|
315
316
|
_startRunLoop();
|
|
@@ -332,12 +333,12 @@ var state = {
|
|
|
332
333
|
/**
|
|
333
334
|
* resume the screen object
|
|
334
335
|
* @name resume
|
|
335
|
-
* @
|
|
336
|
+
* @memberof me.state
|
|
336
337
|
* @public
|
|
337
338
|
* @function
|
|
338
|
-
* @param {
|
|
339
|
+
* @param {boolean} [music=false] resume current music track on screen resume
|
|
339
340
|
*/
|
|
340
|
-
resume(music) {
|
|
341
|
+
resume(music=false) {
|
|
341
342
|
if (this.isPaused()) {
|
|
342
343
|
// resume the main loop
|
|
343
344
|
_resumeRunLoop();
|
|
@@ -357,10 +358,10 @@ var state = {
|
|
|
357
358
|
/**
|
|
358
359
|
* return the running state of the state manager
|
|
359
360
|
* @name isRunning
|
|
360
|
-
* @
|
|
361
|
+
* @memberof me.state
|
|
361
362
|
* @public
|
|
362
363
|
* @function
|
|
363
|
-
* @
|
|
364
|
+
* @returns {boolean} true if a "process is running"
|
|
364
365
|
*/
|
|
365
366
|
isRunning() {
|
|
366
367
|
return _animFrameId !== -1;
|
|
@@ -369,10 +370,10 @@ var state = {
|
|
|
369
370
|
/**
|
|
370
371
|
* Return the pause state of the state manager
|
|
371
372
|
* @name isPaused
|
|
372
|
-
* @
|
|
373
|
+
* @memberof me.state
|
|
373
374
|
* @public
|
|
374
375
|
* @function
|
|
375
|
-
* @
|
|
376
|
+
* @returns {boolean} true if the game is paused
|
|
376
377
|
*/
|
|
377
378
|
isPaused() {
|
|
378
379
|
return _isPaused;
|
|
@@ -381,12 +382,12 @@ var state = {
|
|
|
381
382
|
/**
|
|
382
383
|
* associate the specified state with a Stage
|
|
383
384
|
* @name set
|
|
384
|
-
* @
|
|
385
|
+
* @memberof me.state
|
|
385
386
|
* @public
|
|
386
387
|
* @function
|
|
387
|
-
* @param {
|
|
388
|
+
* @param {number} state State ID (see constants)
|
|
388
389
|
* @param {me.Stage} stage Instantiated Stage to associate with state ID
|
|
389
|
-
* @param {
|
|
390
|
+
* @param {boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
390
391
|
* @example
|
|
391
392
|
* class MenuButton extends me.GUI_Object {
|
|
392
393
|
* onClick() {
|
|
@@ -441,10 +442,10 @@ var state = {
|
|
|
441
442
|
* return a reference to the current screen object<br>
|
|
442
443
|
* useful to call a object specific method
|
|
443
444
|
* @name current
|
|
444
|
-
* @
|
|
445
|
+
* @memberof me.state
|
|
445
446
|
* @public
|
|
446
447
|
* @function
|
|
447
|
-
* @
|
|
448
|
+
* @returns {me.Stage}
|
|
448
449
|
*/
|
|
449
450
|
current() {
|
|
450
451
|
if (typeof _stages[_state] !== "undefined") {
|
|
@@ -455,12 +456,12 @@ var state = {
|
|
|
455
456
|
/**
|
|
456
457
|
* specify a global transition effect
|
|
457
458
|
* @name transition
|
|
458
|
-
* @
|
|
459
|
+
* @memberof me.state
|
|
459
460
|
* @public
|
|
460
461
|
* @function
|
|
461
|
-
* @param {
|
|
462
|
-
* @param {me.Color|
|
|
463
|
-
* @param {
|
|
462
|
+
* @param {string} effect (only "fade" is supported for now)
|
|
463
|
+
* @param {me.Color|string} color a CSS color value
|
|
464
|
+
* @param {number} [duration=1000] expressed in milliseconds
|
|
464
465
|
*/
|
|
465
466
|
transition(effect, color, duration) {
|
|
466
467
|
if (effect === "fade") {
|
|
@@ -472,11 +473,11 @@ var state = {
|
|
|
472
473
|
/**
|
|
473
474
|
* enable/disable transition for a specific state (by default enabled for all)
|
|
474
475
|
* @name setTransition
|
|
475
|
-
* @
|
|
476
|
+
* @memberof me.state
|
|
476
477
|
* @public
|
|
477
478
|
* @function
|
|
478
|
-
* @param {
|
|
479
|
-
* @param {
|
|
479
|
+
* @param {number} state State ID (see constants)
|
|
480
|
+
* @param {boolean} enable
|
|
480
481
|
*/
|
|
481
482
|
setTransition(state, enable) {
|
|
482
483
|
_stages[state].transition = enable;
|
|
@@ -485,12 +486,12 @@ var state = {
|
|
|
485
486
|
/**
|
|
486
487
|
* change the game/app state
|
|
487
488
|
* @name change
|
|
488
|
-
* @
|
|
489
|
+
* @memberof me.state
|
|
489
490
|
* @public
|
|
490
491
|
* @function
|
|
491
|
-
* @param {
|
|
492
|
-
* @param {
|
|
493
|
-
* @param {} [arguments
|
|
492
|
+
* @param {number} state State ID (see constants)
|
|
493
|
+
* @param {boolean} forceChange if true the state will be changed immediately
|
|
494
|
+
* @param {object} [...arguments] extra arguments to be passed to the reset functions
|
|
494
495
|
* @example
|
|
495
496
|
* // The onResetEvent method on the play screen will receive two args:
|
|
496
497
|
* // "level_1" and the number 3
|
|
@@ -502,39 +503,37 @@ var state = {
|
|
|
502
503
|
throw new Error("Undefined Stage for state '" + state + "'");
|
|
503
504
|
}
|
|
504
505
|
|
|
505
|
-
if
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
506
|
+
// do nothing if already the current state
|
|
507
|
+
if (!this.isCurrent(state)) {
|
|
508
|
+
_extraArgs = null;
|
|
509
|
+
if (arguments.length > 1) {
|
|
510
|
+
// store extra arguments if any
|
|
511
|
+
_extraArgs = Array.prototype.slice.call(arguments, 1);
|
|
512
|
+
}
|
|
513
|
+
// if fading effect
|
|
514
|
+
if (_fade.duration && _stages[state].transition) {
|
|
515
|
+
/** @ignore */
|
|
516
|
+
_onSwitchComplete = function() {
|
|
517
|
+
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
518
|
+
};
|
|
519
|
+
game.viewport.fadeIn(
|
|
520
|
+
_fade.color,
|
|
521
|
+
_fade.duration,
|
|
522
|
+
function () {
|
|
523
|
+
fctUtil.defer(_switchState, this, state);
|
|
524
|
+
}
|
|
525
|
+
);
|
|
509
526
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
_onSwitchComplete = function() {
|
|
519
|
-
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
520
|
-
};
|
|
521
|
-
game.viewport.fadeIn(
|
|
522
|
-
_fade.color,
|
|
523
|
-
_fade.duration,
|
|
524
|
-
function () {
|
|
527
|
+
}
|
|
528
|
+
// else just switch without any effects
|
|
529
|
+
else {
|
|
530
|
+
// wait for the last frame to be
|
|
531
|
+
// "finished" before switching
|
|
532
|
+
if (forceChange === true) {
|
|
533
|
+
_switchState(state);
|
|
534
|
+
} else {
|
|
525
535
|
fctUtil.defer(_switchState, this, state);
|
|
526
536
|
}
|
|
527
|
-
);
|
|
528
|
-
|
|
529
|
-
}
|
|
530
|
-
// else just switch without any effects
|
|
531
|
-
else {
|
|
532
|
-
// wait for the last frame to be
|
|
533
|
-
// "finished" before switching
|
|
534
|
-
if (forceChange === true) {
|
|
535
|
-
_switchState(state);
|
|
536
|
-
} else {
|
|
537
|
-
fctUtil.defer(_switchState, this, state);
|
|
538
537
|
}
|
|
539
538
|
}
|
|
540
539
|
},
|
|
@@ -542,10 +541,11 @@ var state = {
|
|
|
542
541
|
/**
|
|
543
542
|
* return true if the specified state is the current one
|
|
544
543
|
* @name isCurrent
|
|
545
|
-
* @
|
|
544
|
+
* @memberof me.state
|
|
546
545
|
* @public
|
|
547
546
|
* @function
|
|
548
|
-
* @param {
|
|
547
|
+
* @param {number} state State ID (see constants)
|
|
548
|
+
* @returns {boolean} true if the specified state is the current one
|
|
549
549
|
*/
|
|
550
550
|
isCurrent(state) {
|
|
551
551
|
return _state === state;
|