melonjs 10.10.0 → 10.11.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 -3
- package/dist/melonjs.js +817 -1922
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +339 -1183
- package/dist/melonjs.module.js +745 -1846
- package/package.json +12 -15
- package/src/audio/audio.js +0 -1
- package/src/camera/camera2d.js +1 -16
- package/src/entity/entity.js +1 -4
- package/src/geometries/ellipse.js +2 -11
- package/src/geometries/line.js +1 -4
- package/src/geometries/path2d.js +0 -10
- package/src/geometries/poly.js +5 -22
- package/src/geometries/rectangle.js +2 -14
- package/src/geometries/roundrect.js +2 -6
- package/src/index.js +0 -1
- package/src/input/gamepad.js +3 -14
- package/src/input/keyboard.js +1 -9
- package/src/input/pointer.js +0 -1
- package/src/input/pointerevent.js +14 -23
- package/src/lang/deprecated.js +4 -3
- package/src/level/level.js +0 -9
- package/src/level/tiled/TMXGroup.js +0 -4
- package/src/level/tiled/TMXLayer.js +0 -8
- package/src/level/tiled/TMXObject.js +0 -3
- package/src/level/tiled/TMXTile.js +4 -5
- package/src/level/tiled/TMXTileMap.js +1 -7
- package/src/level/tiled/TMXTileset.js +0 -5
- package/src/level/tiled/TMXTilesetGroup.js +1 -4
- package/src/level/tiled/TMXUtils.js +0 -3
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +2 -3
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +0 -1
- package/src/level/tiled/renderer/TMXRenderer.js +1 -7
- package/src/loader/loader.js +0 -11
- package/src/loader/loadingscreen.js +1 -1
- package/src/math/color.js +5 -26
- package/src/math/math.js +0 -10
- package/src/math/matrix2.js +12 -27
- package/src/math/matrix3.js +1 -22
- package/src/math/observable_vector2.js +0 -29
- package/src/math/observable_vector3.js +0 -29
- package/src/math/vector2.js +3 -40
- package/src/math/vector3.js +4 -41
- package/src/particles/emitter.js +1 -1
- package/src/physics/body.js +1 -1
- package/src/physics/bounds.js +5 -19
- package/src/physics/collision.js +0 -1
- package/src/physics/detector.js +0 -4
- package/src/physics/quadtree.js +0 -7
- package/src/physics/sat.js +3 -3
- package/src/physics/world.js +0 -4
- package/src/plugin/plugin.js +0 -2
- package/src/polyfill/roundrect.js +4 -2
- package/src/renderable/GUI.js +0 -5
- package/src/renderable/collectable.js +1 -0
- package/src/renderable/container.js +0 -28
- package/src/renderable/dragndrop.js +0 -9
- package/src/renderable/imagelayer.js +1 -5
- package/src/renderable/light2d.js +1 -2
- package/src/renderable/renderable.js +0 -22
- package/src/renderable/sprite.js +0 -12
- package/src/renderable/trigger.js +1 -1
- package/src/state/stage.js +0 -4
- package/src/state/state.js +3 -20
- package/src/system/device.js +14 -53
- package/src/system/event.js +11 -0
- package/src/system/pooling.js +19 -8
- package/src/system/save.js +9 -11
- package/src/system/timer.js +239 -218
- package/src/text/bitmaptextdata.js +1 -4
- package/src/text/glyph.js +2 -2
- package/src/text/text.js +7 -5
- package/src/text/textmetrics.js +0 -2
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +2 -2
- package/src/tweens/tween.js +1 -13
- package/src/utils/agent.js +1 -3
- package/src/utils/array.js +0 -3
- package/src/utils/file.js +0 -2
- package/src/utils/function.js +0 -2
- package/src/utils/string.js +0 -6
- package/src/utils/utils.js +0 -3
- package/src/video/canvas/canvas_renderer.js +4 -39
- package/src/video/renderer.js +1 -23
- package/src/video/texture/cache.js +0 -1
- package/src/video/texture/canvas_texture.js +16 -4
- package/src/video/video.js +3 -3
- package/src/video/webgl/glshader.js +0 -5
- package/src/video/webgl/utils/uniforms.js +3 -6
- package/src/video/webgl/webgl_compositor.js +0 -14
- package/src/video/webgl/webgl_renderer.js +0 -42
package/src/state/state.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { pauseTrack, resumeTrack } from "./../audio/audio.js";
|
|
2
2
|
import * as fctUtil from "./../utils/function.js";
|
|
3
3
|
import * as event from "./../system/event.js";
|
|
4
|
-
import timer from "./../system/timer.js";
|
|
5
4
|
import * as game from "./../game.js";
|
|
6
5
|
import Stage from "./../state/stage.js";
|
|
7
6
|
import DefaultLoadingScreen from "./../loader/loadingscreen.js";
|
|
@@ -41,9 +40,6 @@ var _pauseTime = 0;
|
|
|
41
40
|
function _startRunLoop() {
|
|
42
41
|
// ensure nothing is running first and in valid state
|
|
43
42
|
if ((_animFrameId === -1) && (_state !== -1)) {
|
|
44
|
-
// reset the timer
|
|
45
|
-
timer.reset();
|
|
46
|
-
|
|
47
43
|
// start the main loop
|
|
48
44
|
_animFrameId = globalThis.requestAnimationFrame(_renderFrame);
|
|
49
45
|
}
|
|
@@ -56,9 +52,6 @@ function _startRunLoop() {
|
|
|
56
52
|
function _resumeRunLoop() {
|
|
57
53
|
// ensure game is actually paused and in valid state
|
|
58
54
|
if (_isPaused && (_state !== -1)) {
|
|
59
|
-
// reset the timer
|
|
60
|
-
timer.reset();
|
|
61
|
-
|
|
62
55
|
_isPaused = false;
|
|
63
56
|
}
|
|
64
57
|
}
|
|
@@ -124,6 +117,9 @@ function _switchState(state) {
|
|
|
124
117
|
// new requested state
|
|
125
118
|
_startRunLoop();
|
|
126
119
|
|
|
120
|
+
// publish the pause event
|
|
121
|
+
event.emit(event.STATE_CHANGE);
|
|
122
|
+
|
|
127
123
|
// execute callback if defined
|
|
128
124
|
if (_onSwitchComplete) {
|
|
129
125
|
_onSwitchComplete();
|
|
@@ -253,7 +249,6 @@ var state = {
|
|
|
253
249
|
* @name stop
|
|
254
250
|
* @memberof state
|
|
255
251
|
* @public
|
|
256
|
-
* @function
|
|
257
252
|
* @param {boolean} [pauseTrack=false] pause current track on screen stop.
|
|
258
253
|
*/
|
|
259
254
|
stop(pauseTrack=false) {
|
|
@@ -280,7 +275,6 @@ var state = {
|
|
|
280
275
|
* @name pause
|
|
281
276
|
* @memberof state
|
|
282
277
|
* @public
|
|
283
|
-
* @function
|
|
284
278
|
* @param {boolean} [music=false] pause current music track on screen pause
|
|
285
279
|
*/
|
|
286
280
|
pause(music=false) {
|
|
@@ -306,7 +300,6 @@ var state = {
|
|
|
306
300
|
* @name restart
|
|
307
301
|
* @memberof state
|
|
308
302
|
* @public
|
|
309
|
-
* @function
|
|
310
303
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
311
304
|
*/
|
|
312
305
|
restart(music=false) {
|
|
@@ -334,7 +327,6 @@ var state = {
|
|
|
334
327
|
* @name resume
|
|
335
328
|
* @memberof state
|
|
336
329
|
* @public
|
|
337
|
-
* @function
|
|
338
330
|
* @param {boolean} [music=false] resume current music track on screen resume
|
|
339
331
|
*/
|
|
340
332
|
resume(music=false) {
|
|
@@ -359,7 +351,6 @@ var state = {
|
|
|
359
351
|
* @name isRunning
|
|
360
352
|
* @memberof state
|
|
361
353
|
* @public
|
|
362
|
-
* @function
|
|
363
354
|
* @returns {boolean} true if a "process is running"
|
|
364
355
|
*/
|
|
365
356
|
isRunning() {
|
|
@@ -371,7 +362,6 @@ var state = {
|
|
|
371
362
|
* @name isPaused
|
|
372
363
|
* @memberof state
|
|
373
364
|
* @public
|
|
374
|
-
* @function
|
|
375
365
|
* @returns {boolean} true if the game is paused
|
|
376
366
|
*/
|
|
377
367
|
isPaused() {
|
|
@@ -383,7 +373,6 @@ var state = {
|
|
|
383
373
|
* @name set
|
|
384
374
|
* @memberof state
|
|
385
375
|
* @public
|
|
386
|
-
* @function
|
|
387
376
|
* @param {number} state State ID (see constants)
|
|
388
377
|
* @param {Stage} stage Instantiated Stage to associate with state ID
|
|
389
378
|
* @param {boolean} [start = false] if true the state will be changed immediately after adding it.
|
|
@@ -443,7 +432,6 @@ var state = {
|
|
|
443
432
|
* @name current
|
|
444
433
|
* @memberof state
|
|
445
434
|
* @public
|
|
446
|
-
* @function
|
|
447
435
|
* @returns {Stage}
|
|
448
436
|
*/
|
|
449
437
|
current() {
|
|
@@ -457,7 +445,6 @@ var state = {
|
|
|
457
445
|
* @name transition
|
|
458
446
|
* @memberof state
|
|
459
447
|
* @public
|
|
460
|
-
* @function
|
|
461
448
|
* @param {string} effect (only "fade" is supported for now)
|
|
462
449
|
* @param {Color|string} color a CSS color value
|
|
463
450
|
* @param {number} [duration=1000] expressed in milliseconds
|
|
@@ -474,7 +461,6 @@ var state = {
|
|
|
474
461
|
* @name setTransition
|
|
475
462
|
* @memberof state
|
|
476
463
|
* @public
|
|
477
|
-
* @function
|
|
478
464
|
* @param {number} state State ID (see constants)
|
|
479
465
|
* @param {boolean} enable
|
|
480
466
|
*/
|
|
@@ -487,7 +473,6 @@ var state = {
|
|
|
487
473
|
* @name change
|
|
488
474
|
* @memberof state
|
|
489
475
|
* @public
|
|
490
|
-
* @function
|
|
491
476
|
* @param {number} state State ID (see constants)
|
|
492
477
|
* @param {boolean} forceChange if true the state will be changed immediately
|
|
493
478
|
* @param {object} [...arguments] extra arguments to be passed to the reset functions
|
|
@@ -511,7 +496,6 @@ var state = {
|
|
|
511
496
|
}
|
|
512
497
|
// if fading effect
|
|
513
498
|
if (_fade.duration && _stages[state].transition) {
|
|
514
|
-
/** @ignore */
|
|
515
499
|
_onSwitchComplete = () => {
|
|
516
500
|
game.viewport.fadeOut(_fade.color, _fade.duration);
|
|
517
501
|
};
|
|
@@ -542,7 +526,6 @@ var state = {
|
|
|
542
526
|
* @name isCurrent
|
|
543
527
|
* @memberof state
|
|
544
528
|
* @public
|
|
545
|
-
* @function
|
|
546
529
|
* @param {number} state State ID (see constants)
|
|
547
530
|
* @returns {boolean} true if the specified state is the current one
|
|
548
531
|
*/
|
package/src/system/device.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { hasAudio } from "./../audio/audio.js";
|
|
2
2
|
import { getParent } from "./../video/video.js";
|
|
3
|
-
import save from "
|
|
3
|
+
import save from "./save.js";
|
|
4
4
|
import { prefixed } from "./../utils/agent.js";
|
|
5
5
|
import state from "./../state/state.js";
|
|
6
|
-
import * as event from "
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The device capabilities and specific events
|
|
10
|
-
* @namespace device
|
|
11
|
-
*/
|
|
6
|
+
import * as event from "./event.js";
|
|
12
7
|
|
|
13
8
|
// private properties
|
|
14
9
|
let accelInitialized = false;
|
|
@@ -39,7 +34,7 @@ function _domReady() {
|
|
|
39
34
|
// Make sure that the DOM is not already loaded
|
|
40
35
|
if (!isReady) {
|
|
41
36
|
// be sure document.body is there
|
|
42
|
-
if (
|
|
37
|
+
if (typeof globalThis.document !== "undefined" && !globalThis.document.body) {
|
|
43
38
|
return setTimeout(_domReady, 13);
|
|
44
39
|
}
|
|
45
40
|
|
|
@@ -250,6 +245,11 @@ event.on(event.BOOT, () => {
|
|
|
250
245
|
|
|
251
246
|
|
|
252
247
|
// public export
|
|
248
|
+
/**
|
|
249
|
+
* The device capabilities and specific events
|
|
250
|
+
*
|
|
251
|
+
* @namespace
|
|
252
|
+
*/
|
|
253
253
|
let device = {
|
|
254
254
|
|
|
255
255
|
/**
|
|
@@ -257,7 +257,6 @@ let device = {
|
|
|
257
257
|
* @type {string}
|
|
258
258
|
* @readonly
|
|
259
259
|
* @name ua
|
|
260
|
-
* @memberof device
|
|
261
260
|
*/
|
|
262
261
|
ua : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.userAgent : "",
|
|
263
262
|
|
|
@@ -267,7 +266,6 @@ let device = {
|
|
|
267
266
|
* @type {boolean}
|
|
268
267
|
* @readonly
|
|
269
268
|
* @name localStorage
|
|
270
|
-
* @memberof device
|
|
271
269
|
*/
|
|
272
270
|
localStorage : false,
|
|
273
271
|
|
|
@@ -276,7 +274,6 @@ let device = {
|
|
|
276
274
|
* @type {boolean}
|
|
277
275
|
* @readonly
|
|
278
276
|
* @name hasAccelerometer
|
|
279
|
-
* @memberof device
|
|
280
277
|
*/
|
|
281
278
|
hasAccelerometer : false,
|
|
282
279
|
|
|
@@ -285,7 +282,6 @@ let device = {
|
|
|
285
282
|
* @type {boolean}
|
|
286
283
|
* @readonly
|
|
287
284
|
* @name hasDeviceOrientation
|
|
288
|
-
* @memberof device
|
|
289
285
|
*/
|
|
290
286
|
hasDeviceOrientation : false,
|
|
291
287
|
|
|
@@ -295,7 +291,6 @@ let device = {
|
|
|
295
291
|
* @type {boolean}
|
|
296
292
|
* @readonly
|
|
297
293
|
* @name ScreenOrientation
|
|
298
|
-
* @memberof device
|
|
299
294
|
*/
|
|
300
295
|
ScreenOrientation : false,
|
|
301
296
|
|
|
@@ -304,7 +299,6 @@ let device = {
|
|
|
304
299
|
* @type {boolean}
|
|
305
300
|
* @readonly
|
|
306
301
|
* @name hasFullscreenSupport
|
|
307
|
-
* @memberof device
|
|
308
302
|
*/
|
|
309
303
|
hasFullscreenSupport : false,
|
|
310
304
|
|
|
@@ -313,7 +307,6 @@ let device = {
|
|
|
313
307
|
* @type {boolean}
|
|
314
308
|
* @readonly
|
|
315
309
|
* @name hasPointerLockSupport
|
|
316
|
-
* @memberof device
|
|
317
310
|
*/
|
|
318
311
|
hasPointerLockSupport : false,
|
|
319
312
|
|
|
@@ -322,7 +315,6 @@ let device = {
|
|
|
322
315
|
* @type {boolean}
|
|
323
316
|
* @readonly
|
|
324
317
|
* @name hasWebAudio
|
|
325
|
-
* @memberof device
|
|
326
318
|
*/
|
|
327
319
|
hasWebAudio : false,
|
|
328
320
|
|
|
@@ -331,7 +323,6 @@ let device = {
|
|
|
331
323
|
* @type {boolean}
|
|
332
324
|
* @readonly
|
|
333
325
|
* @name nativeBase64
|
|
334
|
-
* @memberof device
|
|
335
326
|
*/
|
|
336
327
|
nativeBase64 : (typeof(globalThis.atob) === "function"),
|
|
337
328
|
|
|
@@ -340,7 +331,6 @@ let device = {
|
|
|
340
331
|
* @type {number}
|
|
341
332
|
* @readonly
|
|
342
333
|
* @name maxTouchPoints
|
|
343
|
-
* @memberof device
|
|
344
334
|
* @example
|
|
345
335
|
* if (me.device.maxTouchPoints > 1) {
|
|
346
336
|
* // device supports multi-touch
|
|
@@ -353,7 +343,6 @@ let device = {
|
|
|
353
343
|
* @type {boolean}
|
|
354
344
|
* @readonly
|
|
355
345
|
* @name touch
|
|
356
|
-
* @memberof device
|
|
357
346
|
*/
|
|
358
347
|
touch : false,
|
|
359
348
|
|
|
@@ -362,7 +351,6 @@ let device = {
|
|
|
362
351
|
* @type {boolean}
|
|
363
352
|
* @readonly
|
|
364
353
|
* @name wheel
|
|
365
|
-
* @memberof device
|
|
366
354
|
*/
|
|
367
355
|
wheel : false,
|
|
368
356
|
|
|
@@ -372,7 +360,6 @@ let device = {
|
|
|
372
360
|
* @type {boolean}
|
|
373
361
|
* @readonly
|
|
374
362
|
* @name isMobile
|
|
375
|
-
* @memberof device
|
|
376
363
|
*/
|
|
377
364
|
isMobile : false,
|
|
378
365
|
|
|
@@ -381,7 +368,6 @@ let device = {
|
|
|
381
368
|
* @type {boolean}
|
|
382
369
|
* @readonly
|
|
383
370
|
* @name iOS
|
|
384
|
-
* @memberof device
|
|
385
371
|
*/
|
|
386
372
|
iOS : false,
|
|
387
373
|
|
|
@@ -390,7 +376,6 @@ let device = {
|
|
|
390
376
|
* @type {boolean}
|
|
391
377
|
* @readonly
|
|
392
378
|
* @name android
|
|
393
|
-
* @memberof device
|
|
394
379
|
*/
|
|
395
380
|
android : false,
|
|
396
381
|
|
|
@@ -399,7 +384,6 @@ let device = {
|
|
|
399
384
|
* @type {boolean}
|
|
400
385
|
* @readonly
|
|
401
386
|
* @name android2
|
|
402
|
-
* @memberof device
|
|
403
387
|
*/
|
|
404
388
|
android2 : false,
|
|
405
389
|
|
|
@@ -408,7 +392,6 @@ let device = {
|
|
|
408
392
|
* @type {boolean}
|
|
409
393
|
* @readonly
|
|
410
394
|
* @name linux
|
|
411
|
-
* @memberof device
|
|
412
395
|
*/
|
|
413
396
|
linux : false,
|
|
414
397
|
|
|
@@ -418,7 +401,6 @@ let device = {
|
|
|
418
401
|
* @readonly
|
|
419
402
|
* @see http://impactjs.com/ejecta
|
|
420
403
|
* @name ejecta
|
|
421
|
-
* @memberof device
|
|
422
404
|
*/
|
|
423
405
|
ejecta : false,
|
|
424
406
|
|
|
@@ -427,7 +409,6 @@ let device = {
|
|
|
427
409
|
* @type {boolean}
|
|
428
410
|
* @readonly
|
|
429
411
|
* @name isWeixin
|
|
430
|
-
* @memberof device
|
|
431
412
|
*/
|
|
432
413
|
isWeixin : false,
|
|
433
414
|
|
|
@@ -436,7 +417,6 @@ let device = {
|
|
|
436
417
|
* @type {boolean}
|
|
437
418
|
* @readonly
|
|
438
419
|
* @name nodeJS
|
|
439
|
-
* @memberof device
|
|
440
420
|
*/
|
|
441
421
|
nodeJS : (typeof process !== "undefined") && (process.release.name === "node"),
|
|
442
422
|
|
|
@@ -445,7 +425,6 @@ let device = {
|
|
|
445
425
|
* @type {boolean}
|
|
446
426
|
* @readonly
|
|
447
427
|
* @name chromeOS
|
|
448
|
-
* @memberof device
|
|
449
428
|
*/
|
|
450
429
|
chromeOS : false,
|
|
451
430
|
|
|
@@ -454,7 +433,6 @@ let device = {
|
|
|
454
433
|
* @type {boolean}
|
|
455
434
|
* @readonly
|
|
456
435
|
* @name wp
|
|
457
|
-
* @memberof device
|
|
458
436
|
*/
|
|
459
437
|
wp : false,
|
|
460
438
|
|
|
@@ -463,7 +441,6 @@ let device = {
|
|
|
463
441
|
* @type {boolean}
|
|
464
442
|
* @readonly
|
|
465
443
|
* @name BlackBerry
|
|
466
|
-
* @memberof device
|
|
467
444
|
*/
|
|
468
445
|
BlackBerry : false,
|
|
469
446
|
|
|
@@ -472,7 +449,6 @@ let device = {
|
|
|
472
449
|
* @type {boolean}
|
|
473
450
|
* @readonly
|
|
474
451
|
* @name Kindle
|
|
475
|
-
* @memberof device
|
|
476
452
|
*/
|
|
477
453
|
Kindle : false,
|
|
478
454
|
|
|
@@ -483,7 +459,6 @@ let device = {
|
|
|
483
459
|
* @readonly
|
|
484
460
|
* @name accelerationX
|
|
485
461
|
* @see device.watchAccelerometer
|
|
486
|
-
* @memberof device
|
|
487
462
|
*/
|
|
488
463
|
accelerationX : 0,
|
|
489
464
|
|
|
@@ -494,7 +469,6 @@ let device = {
|
|
|
494
469
|
* @readonly
|
|
495
470
|
* @name accelerationY
|
|
496
471
|
* @see device.watchAccelerometer
|
|
497
|
-
* @memberof device
|
|
498
472
|
*/
|
|
499
473
|
accelerationY : 0,
|
|
500
474
|
|
|
@@ -505,7 +479,6 @@ let device = {
|
|
|
505
479
|
* @readonly
|
|
506
480
|
* @name accelerationZ
|
|
507
481
|
* @see device.watchAccelerometer
|
|
508
|
-
* @memberof device
|
|
509
482
|
*/
|
|
510
483
|
accelerationZ : 0,
|
|
511
484
|
|
|
@@ -516,7 +489,6 @@ let device = {
|
|
|
516
489
|
* @readonly
|
|
517
490
|
* @name gamma
|
|
518
491
|
* @see device.watchDeviceOrientation
|
|
519
|
-
* @memberof device
|
|
520
492
|
*/
|
|
521
493
|
gamma : 0,
|
|
522
494
|
|
|
@@ -527,7 +499,6 @@ let device = {
|
|
|
527
499
|
* @readonly
|
|
528
500
|
* @name beta
|
|
529
501
|
* @see device.watchDeviceOrientation
|
|
530
|
-
* @memberof device
|
|
531
502
|
*/
|
|
532
503
|
beta: 0,
|
|
533
504
|
|
|
@@ -539,7 +510,6 @@ let device = {
|
|
|
539
510
|
* @readonly
|
|
540
511
|
* @name alpha
|
|
541
512
|
* @see device.watchDeviceOrientation
|
|
542
|
-
* @memberof device
|
|
543
513
|
*/
|
|
544
514
|
alpha : 0,
|
|
545
515
|
|
|
@@ -551,7 +521,6 @@ let device = {
|
|
|
551
521
|
* @readonly
|
|
552
522
|
* @see http://www.w3schools.com/tags/ref_language_codes.asp
|
|
553
523
|
* @name language
|
|
554
|
-
* @memberof device
|
|
555
524
|
*/
|
|
556
525
|
language : typeof globalThis.navigator !== "undefined" ? globalThis.navigator.language || globalThis.navigator.browserLanguage || globalThis.navigator.userLanguage || "en" : "en",
|
|
557
526
|
|
|
@@ -559,7 +528,6 @@ let device = {
|
|
|
559
528
|
* Specify whether to pause the game when losing focus
|
|
560
529
|
* @type {boolean}
|
|
561
530
|
* @default true
|
|
562
|
-
* @memberof device
|
|
563
531
|
*/
|
|
564
532
|
pauseOnBlur : true,
|
|
565
533
|
|
|
@@ -567,7 +535,6 @@ let device = {
|
|
|
567
535
|
* Specify whether to unpause the game when gaining focus
|
|
568
536
|
* @type {boolean}
|
|
569
537
|
* @default true
|
|
570
|
-
* @memberof device
|
|
571
538
|
*/
|
|
572
539
|
resumeOnFocus : true,
|
|
573
540
|
|
|
@@ -575,7 +542,6 @@ let device = {
|
|
|
575
542
|
* Specify whether to automatically bring the window to the front
|
|
576
543
|
* @type {boolean}
|
|
577
544
|
* @default true
|
|
578
|
-
* @memberof device
|
|
579
545
|
*/
|
|
580
546
|
autoFocus : true,
|
|
581
547
|
|
|
@@ -584,7 +550,6 @@ let device = {
|
|
|
584
550
|
* The engine restarts on focus if this is enabled.
|
|
585
551
|
* @type {boolean}
|
|
586
552
|
* @default false
|
|
587
|
-
* @memberof device
|
|
588
553
|
*/
|
|
589
554
|
stopOnBlur : false,
|
|
590
555
|
|
|
@@ -593,7 +558,6 @@ let device = {
|
|
|
593
558
|
* @type {boolean}
|
|
594
559
|
* @readonly
|
|
595
560
|
* @name OffScreenCanvas
|
|
596
|
-
* @memberof device
|
|
597
561
|
*/
|
|
598
562
|
OffscreenCanvas : false,
|
|
599
563
|
|
|
@@ -1110,10 +1074,9 @@ let device = {
|
|
|
1110
1074
|
|
|
1111
1075
|
/**
|
|
1112
1076
|
* Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
|
|
1113
|
-
* @name devicePixelRatio
|
|
1114
|
-
* @memberof device
|
|
1077
|
+
* @name device.devicePixelRatio
|
|
1115
1078
|
* @public
|
|
1116
|
-
* @
|
|
1079
|
+
* @member {number}
|
|
1117
1080
|
* @readonly
|
|
1118
1081
|
* @returns {number}
|
|
1119
1082
|
*/
|
|
@@ -1128,10 +1091,9 @@ Object.defineProperty(device, "devicePixelRatio", {
|
|
|
1128
1091
|
|
|
1129
1092
|
/**
|
|
1130
1093
|
* Returns true if the browser/device is in full screen mode.
|
|
1131
|
-
* @name isFullscreen
|
|
1132
|
-
* @memberof device
|
|
1094
|
+
* @name device.isFullscreen
|
|
1133
1095
|
* @public
|
|
1134
|
-
* @
|
|
1096
|
+
* @member {boolean}
|
|
1135
1097
|
* @readonly
|
|
1136
1098
|
* @returns {boolean}
|
|
1137
1099
|
*/
|
|
@@ -1151,10 +1113,9 @@ Object.defineProperty(device, "isFullscreen", {
|
|
|
1151
1113
|
|
|
1152
1114
|
/**
|
|
1153
1115
|
* Returns true if the browser/device has audio capabilities.
|
|
1154
|
-
* @name sound
|
|
1155
|
-
* @memberof device
|
|
1116
|
+
* @name device.sound
|
|
1156
1117
|
* @public
|
|
1157
|
-
* @
|
|
1118
|
+
* @member {boolean}
|
|
1158
1119
|
* @readonly
|
|
1159
1120
|
* @returns {boolean}
|
|
1160
1121
|
*/
|
package/src/system/event.js
CHANGED
|
@@ -67,6 +67,17 @@ export const STATE_STOP = "me.state.onStop";
|
|
|
67
67
|
*/
|
|
68
68
|
export const STATE_RESTART = "me.state.onRestart";
|
|
69
69
|
|
|
70
|
+
/**
|
|
71
|
+
* event for when the changing to a different stage
|
|
72
|
+
* @public
|
|
73
|
+
* @constant
|
|
74
|
+
* @type {string}
|
|
75
|
+
* @name STATE_CHANGE
|
|
76
|
+
* @memberof event
|
|
77
|
+
* @see event.on
|
|
78
|
+
*/
|
|
79
|
+
export const STATE_CHANGE = "me.state.onChange";
|
|
80
|
+
|
|
70
81
|
/**
|
|
71
82
|
* event for when the video is initialized<br>
|
|
72
83
|
* Data passed : none <br>
|
package/src/system/pooling.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @classdesc
|
|
3
|
-
*
|
|
3
|
+
* Object pooling - a technique that might speed up your game if used properly.<br>
|
|
4
4
|
* If some of your classes will be instantiated and removed a lot at a time, it is a
|
|
5
5
|
* good idea to add the class to this object pool. A separate pool for that class
|
|
6
6
|
* will be created, which will reuse objects of the class. That way they won't be instantiated
|
|
7
7
|
* each time you need a new one (slowing your game), but stored into that pool and taking one
|
|
8
8
|
* already instantiated when you need it.<br><br>
|
|
9
|
-
* This
|
|
9
|
+
* This technique is also used by the engine to instantiate objects defined in the map,
|
|
10
10
|
* which means, that on level loading the engine will try to instantiate every object
|
|
11
11
|
* found in the map, based on the user defined name in each Object Properties<br>
|
|
12
12
|
* <img src="images/object_properties.png"/><br>
|
|
13
|
-
* @see {@link pool}
|
|
13
|
+
* @see {@link pool} the default global instance of ObjectPool
|
|
14
14
|
*/
|
|
15
15
|
class ObjectPool {
|
|
16
16
|
|
|
@@ -180,11 +180,22 @@ class ObjectPool {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
* a default global object pool instance
|
|
185
|
-
* @public
|
|
186
|
-
* @type {ObjectPool}
|
|
187
|
-
*/
|
|
183
|
+
|
|
188
184
|
var pool = new ObjectPool();
|
|
189
185
|
|
|
186
|
+
/**
|
|
187
|
+
* a default global ObjectPool instance
|
|
188
|
+
* @namespace pool
|
|
189
|
+
* @see ObjectPool
|
|
190
|
+
* @example
|
|
191
|
+
* // register our bullet object into the object pool
|
|
192
|
+
* pool.register("bullet", BulletEntity, true);
|
|
193
|
+
* // ...
|
|
194
|
+
* // when we need to manually create a new bullet:
|
|
195
|
+
* var bullet = pool.pull("bullet", x, y, direction, velocity);
|
|
196
|
+
* // ...
|
|
197
|
+
* // when we want to destroy existing object, the remove
|
|
198
|
+
* // function will ensure the object can then be reallocated later
|
|
199
|
+
* game.world.removeChild(bullet);
|
|
200
|
+
*/
|
|
190
201
|
export default pool;
|
package/src/system/save.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import device from "
|
|
2
|
-
import * as event from "
|
|
1
|
+
import device from "./device.js";
|
|
2
|
+
import * as event from "./event.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* allow to access and manage the device localStorage
|
|
@@ -47,13 +47,13 @@ import * as event from "./../system/event.js";
|
|
|
47
47
|
// Initialize me.save on Boot event
|
|
48
48
|
event.on(event.BOOT, () => {
|
|
49
49
|
// Load previous data if local Storage is supported
|
|
50
|
-
if (
|
|
51
|
-
var me_save_content = localStorage.getItem("me.save");
|
|
50
|
+
if (typeof globalThis.localStorage !== "undefined") {
|
|
51
|
+
var me_save_content = globalThis.localStorage.getItem("me.save");
|
|
52
52
|
|
|
53
53
|
if (typeof me_save_content === "string" && me_save_content.length > 0) {
|
|
54
54
|
var keys = JSON.parse(me_save_content) || [];
|
|
55
55
|
keys.forEach(function (key) {
|
|
56
|
-
data[key] = JSON.parse(localStorage.getItem("me.save." + key));
|
|
56
|
+
data[key] = JSON.parse(globalThis.localStorage.getItem("me.save." + key));
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -65,7 +65,6 @@ var save = {
|
|
|
65
65
|
* Add new keys to localStorage and set them to the given default values if they do not exist
|
|
66
66
|
* @name add
|
|
67
67
|
* @memberof save
|
|
68
|
-
* @function
|
|
69
68
|
* @param {object} props key and corresponding values
|
|
70
69
|
* @example
|
|
71
70
|
* // Initialize "score" and "lives" with default values
|
|
@@ -97,7 +96,7 @@ var save = {
|
|
|
97
96
|
set (value) {
|
|
98
97
|
data[prop] = value;
|
|
99
98
|
if (device.localStorage === true) {
|
|
100
|
-
localStorage.setItem("me.save." + prop, JSON.stringify(value));
|
|
99
|
+
globalThis.localStorage.setItem("me.save." + prop, JSON.stringify(value));
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
});
|
|
@@ -111,7 +110,7 @@ var save = {
|
|
|
111
110
|
|
|
112
111
|
// Save keys
|
|
113
112
|
if (device.localStorage === true) {
|
|
114
|
-
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
113
|
+
globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
115
114
|
}
|
|
116
115
|
},
|
|
117
116
|
|
|
@@ -119,7 +118,6 @@ var save = {
|
|
|
119
118
|
* Remove a key from localStorage
|
|
120
119
|
* @name remove
|
|
121
120
|
* @memberof save
|
|
122
|
-
* @function
|
|
123
121
|
* @param {string} key key to be removed
|
|
124
122
|
* @example
|
|
125
123
|
* // Remove the "score" key from localStorage
|
|
@@ -130,8 +128,8 @@ var save = {
|
|
|
130
128
|
if (typeof data[key] !== "undefined") {
|
|
131
129
|
delete data[key];
|
|
132
130
|
if (device.localStorage === true) {
|
|
133
|
-
localStorage.removeItem("me.save." + key);
|
|
134
|
-
localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
131
|
+
globalThis.localStorage.removeItem("me.save." + key);
|
|
132
|
+
globalThis.localStorage.setItem("me.save", JSON.stringify(Object.keys(data)));
|
|
135
133
|
}
|
|
136
134
|
}
|
|
137
135
|
}
|