melonjs 10.2.3 → 10.5.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 +6 -6
- package/dist/melonjs.js +3620 -3582
- package/dist/melonjs.min.js +5 -5
- package/dist/melonjs.module.d.ts +3646 -4545
- package/dist/melonjs.module.js +3912 -3521
- package/package.json +21 -20
- package/src/audio/audio.js +30 -31
- package/src/camera/camera2d.js +47 -58
- package/src/entity/entity.js +32 -38
- package/src/game.js +21 -22
- package/src/{shapes → geometries}/ellipse.js +40 -47
- package/src/{shapes → geometries}/line.js +9 -12
- package/src/{shapes → geometries}/poly.js +100 -53
- package/src/{shapes → geometries}/rectangle.js +42 -45
- package/src/index.js +14 -32
- package/src/input/gamepad.js +11 -10
- package/src/input/input.js +2 -3
- package/src/input/keyboard.js +113 -113
- package/src/input/pointer.js +61 -29
- package/src/input/pointerevent.js +92 -29
- package/src/lang/deprecated.js +83 -13
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -9
- package/src/level/tiled/TMXLayer.js +30 -33
- package/src/level/tiled/TMXObject.js +59 -53
- package/src/level/tiled/TMXTile.js +18 -19
- package/src/level/tiled/TMXTileMap.js +40 -46
- package/src/level/tiled/TMXTileset.js +12 -16
- package/src/level/tiled/TMXTilesetGroup.js +9 -10
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -9
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -6
- package/src/level/tiled/renderer/TMXRenderer.js +24 -26
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -5
- package/src/loader/loader.js +17 -16
- package/src/loader/loadingscreen.js +2 -5
- package/src/math/color.js +47 -67
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -59
- package/src/math/matrix3.js +56 -63
- package/src/math/observable_vector2.js +87 -77
- package/src/math/observable_vector3.js +97 -80
- package/src/math/vector2.js +107 -97
- package/src/math/vector3.js +116 -100
- package/src/particles/emitter.js +66 -76
- package/src/particles/particle.js +4 -6
- package/src/particles/particlecontainer.js +2 -4
- package/src/physics/body.js +49 -147
- package/src/physics/bounds.js +48 -50
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -20
- package/src/physics/sat.js +30 -30
- package/src/physics/world.js +24 -29
- package/src/plugin/plugin.js +11 -15
- package/src/renderable/GUI.js +41 -47
- package/src/renderable/collectable.js +5 -10
- package/src/renderable/colorlayer.js +10 -15
- package/src/renderable/container.js +87 -73
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -32
- package/src/renderable/nineslicesprite.js +41 -42
- package/src/renderable/renderable.js +113 -124
- package/src/renderable/sprite.js +62 -69
- package/src/renderable/trigger.js +26 -32
- package/src/state/stage.js +13 -18
- package/src/state/state.js +26 -27
- package/src/system/device.js +76 -133
- package/src/system/event.js +81 -70
- package/src/system/pooling.js +11 -12
- package/src/system/save.js +3 -4
- package/src/system/timer.js +19 -20
- package/src/text/bitmaptext.js +57 -55
- package/src/text/bitmaptextdata.js +10 -11
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +49 -55
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +44 -46
- package/src/utils/agent.js +3 -4
- package/src/utils/array.js +4 -5
- package/src/utils/file.js +3 -4
- package/src/utils/function.js +4 -5
- package/src/utils/string.js +7 -9
- package/src/utils/utils.js +4 -5
- package/src/video/canvas/canvas_renderer.js +60 -62
- package/src/video/renderer.js +53 -58
- package/src/video/texture.js +98 -112
- package/src/video/texture_cache.js +26 -10
- package/src/video/video.js +15 -16
- package/src/video/webgl/buffer/vertex.js +2 -2
- package/src/video/webgl/glshader.js +37 -39
- package/src/video/webgl/webgl_compositor.js +128 -101
- package/src/video/webgl/webgl_renderer.js +126 -106
- package/src/entity/draggable.js +0 -139
- package/src/entity/droptarget.js +0 -109
package/src/system/device.js
CHANGED
|
@@ -7,8 +7,7 @@ import * as event from "./../system/event.js";
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The device capabilities and specific events
|
|
10
|
-
* @namespace
|
|
11
|
-
* @memberOf me
|
|
10
|
+
* @namespace device
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
// private properties
|
|
@@ -131,12 +130,8 @@ function _checkCapabilities() {
|
|
|
131
130
|
// Modern browsers support "wheel", Webkit and IE support at least "mousewheel
|
|
132
131
|
device.wheel = ("onwheel" in document.createElement("div"));
|
|
133
132
|
|
|
134
|
-
// pointerlock detection
|
|
135
|
-
device.hasPointerLockSupport =
|
|
136
|
-
|
|
137
|
-
if (device.hasPointerLockSupport) {
|
|
138
|
-
document.exitPointerLock = prefixed("exitPointerLock", document);
|
|
139
|
-
}
|
|
133
|
+
// pointerlock detection (pointerLockElement can be null when the feature is supported)
|
|
134
|
+
device.hasPointerLockSupport = typeof document.pointerLockElement !== "undefined";
|
|
140
135
|
|
|
141
136
|
// device orientation and motion detection
|
|
142
137
|
device.hasDeviceOrientation = !!window.DeviceOrientationEvent;
|
|
@@ -257,7 +252,7 @@ let device = {
|
|
|
257
252
|
* @type {string}
|
|
258
253
|
* @readonly
|
|
259
254
|
* @name ua
|
|
260
|
-
* @
|
|
255
|
+
* @memberof device
|
|
261
256
|
*/
|
|
262
257
|
ua : navigator.userAgent,
|
|
263
258
|
|
|
@@ -267,7 +262,7 @@ let device = {
|
|
|
267
262
|
* @type {boolean}
|
|
268
263
|
* @readonly
|
|
269
264
|
* @name localStorage
|
|
270
|
-
* @
|
|
265
|
+
* @memberof device
|
|
271
266
|
*/
|
|
272
267
|
localStorage : false,
|
|
273
268
|
|
|
@@ -276,7 +271,7 @@ let device = {
|
|
|
276
271
|
* @type {boolean}
|
|
277
272
|
* @readonly
|
|
278
273
|
* @name hasAccelerometer
|
|
279
|
-
* @
|
|
274
|
+
* @memberof device
|
|
280
275
|
*/
|
|
281
276
|
hasAccelerometer : false,
|
|
282
277
|
|
|
@@ -285,7 +280,7 @@ let device = {
|
|
|
285
280
|
* @type {boolean}
|
|
286
281
|
* @readonly
|
|
287
282
|
* @name hasDeviceOrientation
|
|
288
|
-
* @
|
|
283
|
+
* @memberof device
|
|
289
284
|
*/
|
|
290
285
|
hasDeviceOrientation : false,
|
|
291
286
|
|
|
@@ -295,7 +290,7 @@ let device = {
|
|
|
295
290
|
* @type {boolean}
|
|
296
291
|
* @readonly
|
|
297
292
|
* @name ScreenOrientation
|
|
298
|
-
* @
|
|
293
|
+
* @memberof device
|
|
299
294
|
*/
|
|
300
295
|
ScreenOrientation : false,
|
|
301
296
|
|
|
@@ -304,7 +299,7 @@ let device = {
|
|
|
304
299
|
* @type {boolean}
|
|
305
300
|
* @readonly
|
|
306
301
|
* @name hasFullscreenSupport
|
|
307
|
-
* @
|
|
302
|
+
* @memberof device
|
|
308
303
|
*/
|
|
309
304
|
hasFullscreenSupport : false,
|
|
310
305
|
|
|
@@ -313,7 +308,7 @@ let device = {
|
|
|
313
308
|
* @type {boolean}
|
|
314
309
|
* @readonly
|
|
315
310
|
* @name hasPointerLockSupport
|
|
316
|
-
* @
|
|
311
|
+
* @memberof device
|
|
317
312
|
*/
|
|
318
313
|
hasPointerLockSupport : false,
|
|
319
314
|
|
|
@@ -322,7 +317,7 @@ let device = {
|
|
|
322
317
|
* @type {boolean}
|
|
323
318
|
* @readonly
|
|
324
319
|
* @name hasWebAudio
|
|
325
|
-
* @
|
|
320
|
+
* @memberof device
|
|
326
321
|
*/
|
|
327
322
|
hasWebAudio : false,
|
|
328
323
|
|
|
@@ -331,7 +326,7 @@ let device = {
|
|
|
331
326
|
* @type {boolean}
|
|
332
327
|
* @readonly
|
|
333
328
|
* @name nativeBase64
|
|
334
|
-
* @
|
|
329
|
+
* @memberof device
|
|
335
330
|
*/
|
|
336
331
|
nativeBase64 : (typeof(window.atob) === "function"),
|
|
337
332
|
|
|
@@ -340,7 +335,7 @@ let device = {
|
|
|
340
335
|
* @type {number}
|
|
341
336
|
* @readonly
|
|
342
337
|
* @name maxTouchPoints
|
|
343
|
-
* @
|
|
338
|
+
* @memberof device
|
|
344
339
|
* @example
|
|
345
340
|
* if (me.device.maxTouchPoints > 1) {
|
|
346
341
|
* // device supports multi-touch
|
|
@@ -353,7 +348,7 @@ let device = {
|
|
|
353
348
|
* @type {boolean}
|
|
354
349
|
* @readonly
|
|
355
350
|
* @name touch
|
|
356
|
-
* @
|
|
351
|
+
* @memberof device
|
|
357
352
|
*/
|
|
358
353
|
touch : false,
|
|
359
354
|
|
|
@@ -362,7 +357,7 @@ let device = {
|
|
|
362
357
|
* @type {boolean}
|
|
363
358
|
* @readonly
|
|
364
359
|
* @name wheel
|
|
365
|
-
* @
|
|
360
|
+
* @memberof device
|
|
366
361
|
*/
|
|
367
362
|
wheel : false,
|
|
368
363
|
|
|
@@ -372,7 +367,7 @@ let device = {
|
|
|
372
367
|
* @type {boolean}
|
|
373
368
|
* @readonly
|
|
374
369
|
* @name isMobile
|
|
375
|
-
* @
|
|
370
|
+
* @memberof device
|
|
376
371
|
*/
|
|
377
372
|
isMobile : false,
|
|
378
373
|
|
|
@@ -381,7 +376,7 @@ let device = {
|
|
|
381
376
|
* @type {boolean}
|
|
382
377
|
* @readonly
|
|
383
378
|
* @name iOS
|
|
384
|
-
* @
|
|
379
|
+
* @memberof device
|
|
385
380
|
*/
|
|
386
381
|
iOS : false,
|
|
387
382
|
|
|
@@ -390,7 +385,7 @@ let device = {
|
|
|
390
385
|
* @type {boolean}
|
|
391
386
|
* @readonly
|
|
392
387
|
* @name android
|
|
393
|
-
* @
|
|
388
|
+
* @memberof device
|
|
394
389
|
*/
|
|
395
390
|
android : false,
|
|
396
391
|
|
|
@@ -399,7 +394,7 @@ let device = {
|
|
|
399
394
|
* @type {boolean}
|
|
400
395
|
* @readonly
|
|
401
396
|
* @name android2
|
|
402
|
-
* @
|
|
397
|
+
* @memberof device
|
|
403
398
|
*/
|
|
404
399
|
android2 : false,
|
|
405
400
|
|
|
@@ -408,7 +403,7 @@ let device = {
|
|
|
408
403
|
* @type {boolean}
|
|
409
404
|
* @readonly
|
|
410
405
|
* @name linux
|
|
411
|
-
* @
|
|
406
|
+
* @memberof device
|
|
412
407
|
*/
|
|
413
408
|
linux : false,
|
|
414
409
|
|
|
@@ -418,7 +413,7 @@ let device = {
|
|
|
418
413
|
* @readonly
|
|
419
414
|
* @see http://impactjs.com/ejecta
|
|
420
415
|
* @name ejecta
|
|
421
|
-
* @
|
|
416
|
+
* @memberof device
|
|
422
417
|
*/
|
|
423
418
|
ejecta : false,
|
|
424
419
|
|
|
@@ -427,7 +422,7 @@ let device = {
|
|
|
427
422
|
* @type {boolean}
|
|
428
423
|
* @readonly
|
|
429
424
|
* @name isWeixin
|
|
430
|
-
* @
|
|
425
|
+
* @memberof device
|
|
431
426
|
*/
|
|
432
427
|
isWeixin : false,
|
|
433
428
|
|
|
@@ -436,7 +431,7 @@ let device = {
|
|
|
436
431
|
* @type {boolean}
|
|
437
432
|
* @readonly
|
|
438
433
|
* @name chromeOS
|
|
439
|
-
* @
|
|
434
|
+
* @memberof device
|
|
440
435
|
*/
|
|
441
436
|
chromeOS : false,
|
|
442
437
|
|
|
@@ -445,7 +440,7 @@ let device = {
|
|
|
445
440
|
* @type {boolean}
|
|
446
441
|
* @readonly
|
|
447
442
|
* @name wp
|
|
448
|
-
* @
|
|
443
|
+
* @memberof device
|
|
449
444
|
*/
|
|
450
445
|
wp : false,
|
|
451
446
|
|
|
@@ -454,7 +449,7 @@ let device = {
|
|
|
454
449
|
* @type {boolean}
|
|
455
450
|
* @readonly
|
|
456
451
|
* @name BlackBerry
|
|
457
|
-
* @
|
|
452
|
+
* @memberof device
|
|
458
453
|
*/
|
|
459
454
|
BlackBerry : false,
|
|
460
455
|
|
|
@@ -463,7 +458,7 @@ let device = {
|
|
|
463
458
|
* @type {boolean}
|
|
464
459
|
* @readonly
|
|
465
460
|
* @name Kindle
|
|
466
|
-
* @
|
|
461
|
+
* @memberof device
|
|
467
462
|
*/
|
|
468
463
|
Kindle : false,
|
|
469
464
|
|
|
@@ -473,8 +468,8 @@ let device = {
|
|
|
473
468
|
* @type {number}
|
|
474
469
|
* @readonly
|
|
475
470
|
* @name accelerationX
|
|
476
|
-
* @see
|
|
477
|
-
* @
|
|
471
|
+
* @see device.watchAccelerometer
|
|
472
|
+
* @memberof device
|
|
478
473
|
*/
|
|
479
474
|
accelerationX : 0,
|
|
480
475
|
|
|
@@ -484,8 +479,8 @@ let device = {
|
|
|
484
479
|
* @type {number}
|
|
485
480
|
* @readonly
|
|
486
481
|
* @name accelerationY
|
|
487
|
-
* @see
|
|
488
|
-
* @
|
|
482
|
+
* @see device.watchAccelerometer
|
|
483
|
+
* @memberof device
|
|
489
484
|
*/
|
|
490
485
|
accelerationY : 0,
|
|
491
486
|
|
|
@@ -495,8 +490,8 @@ let device = {
|
|
|
495
490
|
* @type {number}
|
|
496
491
|
* @readonly
|
|
497
492
|
* @name accelerationZ
|
|
498
|
-
* @see
|
|
499
|
-
* @
|
|
493
|
+
* @see device.watchAccelerometer
|
|
494
|
+
* @memberof device
|
|
500
495
|
*/
|
|
501
496
|
accelerationZ : 0,
|
|
502
497
|
|
|
@@ -506,8 +501,8 @@ let device = {
|
|
|
506
501
|
* @type {number}
|
|
507
502
|
* @readonly
|
|
508
503
|
* @name gamma
|
|
509
|
-
* @see
|
|
510
|
-
* @
|
|
504
|
+
* @see device.watchDeviceOrientation
|
|
505
|
+
* @memberof device
|
|
511
506
|
*/
|
|
512
507
|
gamma : 0,
|
|
513
508
|
|
|
@@ -517,8 +512,8 @@ let device = {
|
|
|
517
512
|
* @type {number}
|
|
518
513
|
* @readonly
|
|
519
514
|
* @name beta
|
|
520
|
-
* @see
|
|
521
|
-
* @
|
|
515
|
+
* @see device.watchDeviceOrientation
|
|
516
|
+
* @memberof device
|
|
522
517
|
*/
|
|
523
518
|
beta: 0,
|
|
524
519
|
|
|
@@ -529,8 +524,8 @@ let device = {
|
|
|
529
524
|
* @type {number}
|
|
530
525
|
* @readonly
|
|
531
526
|
* @name alpha
|
|
532
|
-
* @see
|
|
533
|
-
* @
|
|
527
|
+
* @see device.watchDeviceOrientation
|
|
528
|
+
* @memberof device
|
|
534
529
|
*/
|
|
535
530
|
alpha : 0,
|
|
536
531
|
|
|
@@ -542,7 +537,7 @@ let device = {
|
|
|
542
537
|
* @readonly
|
|
543
538
|
* @see http://www.w3schools.com/tags/ref_language_codes.asp
|
|
544
539
|
* @name language
|
|
545
|
-
* @
|
|
540
|
+
* @memberof device
|
|
546
541
|
*/
|
|
547
542
|
language : navigator.language || navigator.browserLanguage || navigator.userLanguage || "en",
|
|
548
543
|
|
|
@@ -550,7 +545,7 @@ let device = {
|
|
|
550
545
|
* Specify whether to pause the game when losing focus
|
|
551
546
|
* @type {boolean}
|
|
552
547
|
* @default true
|
|
553
|
-
* @
|
|
548
|
+
* @memberof device
|
|
554
549
|
*/
|
|
555
550
|
pauseOnBlur : true,
|
|
556
551
|
|
|
@@ -558,7 +553,7 @@ let device = {
|
|
|
558
553
|
* Specify whether to unpause the game when gaining focus
|
|
559
554
|
* @type {boolean}
|
|
560
555
|
* @default true
|
|
561
|
-
* @
|
|
556
|
+
* @memberof device
|
|
562
557
|
*/
|
|
563
558
|
resumeOnFocus : true,
|
|
564
559
|
|
|
@@ -566,7 +561,7 @@ let device = {
|
|
|
566
561
|
* Specify whether to automatically bring the window to the front
|
|
567
562
|
* @type {boolean}
|
|
568
563
|
* @default true
|
|
569
|
-
* @
|
|
564
|
+
* @memberof device
|
|
570
565
|
*/
|
|
571
566
|
autoFocus : true,
|
|
572
567
|
|
|
@@ -575,7 +570,7 @@ let device = {
|
|
|
575
570
|
* The engine restarts on focus if this is enabled.
|
|
576
571
|
* @type {boolean}
|
|
577
572
|
* @default false
|
|
578
|
-
* @
|
|
573
|
+
* @memberof device
|
|
579
574
|
*/
|
|
580
575
|
stopOnBlur : false,
|
|
581
576
|
|
|
@@ -584,14 +579,14 @@ let device = {
|
|
|
584
579
|
* @type {boolean}
|
|
585
580
|
* @readonly
|
|
586
581
|
* @name OffScreenCanvas
|
|
587
|
-
* @
|
|
582
|
+
* @memberof device
|
|
588
583
|
*/
|
|
589
584
|
OffscreenCanvas : false,
|
|
590
585
|
|
|
591
586
|
|
|
592
587
|
/**
|
|
593
588
|
* specify a function to execute when the Device is fully loaded and ready
|
|
594
|
-
* @function
|
|
589
|
+
* @function device.onReady
|
|
595
590
|
* @param {Function} fn the function to be executed
|
|
596
591
|
* @example
|
|
597
592
|
* // small game skeleton
|
|
@@ -664,7 +659,7 @@ let device = {
|
|
|
664
659
|
|
|
665
660
|
/**
|
|
666
661
|
* enable/disable swipe on WebView.
|
|
667
|
-
* @function
|
|
662
|
+
* @function device.enableSwipe
|
|
668
663
|
* @param {boolean} [enable=true] enable or disable swipe.
|
|
669
664
|
*/
|
|
670
665
|
enableSwipe(enable) {
|
|
@@ -681,7 +676,7 @@ let device = {
|
|
|
681
676
|
|
|
682
677
|
/**
|
|
683
678
|
* Triggers a fullscreen request. Requires fullscreen support from the browser/device.
|
|
684
|
-
* @function
|
|
679
|
+
* @function device.requestFullscreen
|
|
685
680
|
* @param {object} [element=default canvas object] the element to be set in full-screen mode.
|
|
686
681
|
* @example
|
|
687
682
|
* // add a keyboard shortcut to toggle Fullscreen mode on/off
|
|
@@ -709,7 +704,7 @@ let device = {
|
|
|
709
704
|
|
|
710
705
|
/**
|
|
711
706
|
* Exit fullscreen mode. Requires fullscreen support from the browser/device.
|
|
712
|
-
* @function
|
|
707
|
+
* @function device.exitFullscreen
|
|
713
708
|
*/
|
|
714
709
|
exitFullscreen() {
|
|
715
710
|
if (this.hasFullscreenSupport) {
|
|
@@ -720,7 +715,7 @@ let device = {
|
|
|
720
715
|
/**
|
|
721
716
|
* Return a string representing the orientation of the device screen.
|
|
722
717
|
* It can be "any", "natural", "landscape", "portrait", "portrait-primary", "portrait-secondary", "landscape-primary", "landscape-secondary"
|
|
723
|
-
* @function
|
|
718
|
+
* @function device.getScreenOrientation
|
|
724
719
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
|
|
725
720
|
* @returns {string} the screen orientation
|
|
726
721
|
*/
|
|
@@ -754,7 +749,7 @@ let device = {
|
|
|
754
749
|
/**
|
|
755
750
|
* locks the device screen into the specified orientation.<br>
|
|
756
751
|
* This method only works for installed Web apps or for Web pages in full-screen mode.
|
|
757
|
-
* @function
|
|
752
|
+
* @function device.lockOrientation
|
|
758
753
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation
|
|
759
754
|
* @param {string|string[]} orientation The orientation into which to lock the screen.
|
|
760
755
|
* @returns {boolean} true if the orientation was unsuccessfully locked
|
|
@@ -773,7 +768,7 @@ let device = {
|
|
|
773
768
|
/**
|
|
774
769
|
* unlocks the device screen into the specified orientation.<br>
|
|
775
770
|
* This method only works for installed Web apps or for Web pages in full-screen mode.
|
|
776
|
-
* @function
|
|
771
|
+
* @function device.unlockOrientation
|
|
777
772
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Screen/lockOrientation
|
|
778
773
|
* @returns {boolean} true if the orientation was unsuccessfully unlocked
|
|
779
774
|
*/
|
|
@@ -790,7 +785,7 @@ let device = {
|
|
|
790
785
|
|
|
791
786
|
/**
|
|
792
787
|
* return true if the device screen orientation is in Portrait mode
|
|
793
|
-
* @function
|
|
788
|
+
* @function device.isPortrait
|
|
794
789
|
* @returns {boolean}
|
|
795
790
|
*/
|
|
796
791
|
isPortrait() {
|
|
@@ -799,7 +794,7 @@ let device = {
|
|
|
799
794
|
|
|
800
795
|
/**
|
|
801
796
|
* return true if the device screen orientation is in Portrait mode
|
|
802
|
-
* @function
|
|
797
|
+
* @function device.isLandscape
|
|
803
798
|
* @returns {boolean}
|
|
804
799
|
*/
|
|
805
800
|
isLandscape() {
|
|
@@ -808,8 +803,8 @@ let device = {
|
|
|
808
803
|
|
|
809
804
|
/**
|
|
810
805
|
* return the device storage
|
|
811
|
-
* @function
|
|
812
|
-
* @see
|
|
806
|
+
* @function device.getStorage
|
|
807
|
+
* @see save
|
|
813
808
|
* @param {string} [type="local"]
|
|
814
809
|
* @returns {object} a reference to the device storage
|
|
815
810
|
*/
|
|
@@ -825,7 +820,7 @@ let device = {
|
|
|
825
820
|
|
|
826
821
|
/**
|
|
827
822
|
* return the parent DOM element for the given parent name or HTMLElement object
|
|
828
|
-
* @function
|
|
823
|
+
* @function device.getParentElement
|
|
829
824
|
* @param {string|HTMLElement} element the parent element name or a HTMLElement object
|
|
830
825
|
* @returns {HTMLElement} the parent Element
|
|
831
826
|
*/
|
|
@@ -841,7 +836,7 @@ let device = {
|
|
|
841
836
|
|
|
842
837
|
/**
|
|
843
838
|
* return the DOM element for the given element name or HTMLElement object
|
|
844
|
-
* @function
|
|
839
|
+
* @function device.getElement
|
|
845
840
|
* @param {string|HTMLElement} element the parent element name or a HTMLElement object
|
|
846
841
|
* @returns {HTMLElement} the corresponding DOM Element or null if not existing
|
|
847
842
|
*/
|
|
@@ -869,7 +864,7 @@ let device = {
|
|
|
869
864
|
* returns the size of the given HTMLElement and its position relative to the viewport
|
|
870
865
|
* <br><img src="images/element-box-diagram.png"/>
|
|
871
866
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
|
|
872
|
-
* @function
|
|
867
|
+
* @function device.getElementBounds
|
|
873
868
|
* @param {string|HTMLElement} element an HTMLElement object
|
|
874
869
|
* @returns {DOMRect} the size and position of the element relatively to the viewport
|
|
875
870
|
*/
|
|
@@ -887,7 +882,7 @@ let device = {
|
|
|
887
882
|
* returns the size of the given HTMLElement Parent and its position relative to the viewport
|
|
888
883
|
* <br><img src="images/element-box-diagram.png"/>
|
|
889
884
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/DOMRect
|
|
890
|
-
* @function
|
|
885
|
+
* @function device.getParentBounds
|
|
891
886
|
* @param {string|HTMLElement} element an HTMLElement object
|
|
892
887
|
* @returns {DOMRect} the size and position of the given element parent relative to the viewport
|
|
893
888
|
*/
|
|
@@ -897,7 +892,7 @@ let device = {
|
|
|
897
892
|
|
|
898
893
|
/**
|
|
899
894
|
* returns true if the device supports WebGL
|
|
900
|
-
* @function
|
|
895
|
+
* @function device.isWebGLSupported
|
|
901
896
|
* @param {object} [options] context creation options
|
|
902
897
|
* @param {boolean} [options.failIfMajorPerformanceCaveat=true] If true, the renderer will switch to CANVAS mode if the performances of a WebGL context would be dramatically lower than that of a native application making equivalent OpenGL calls.
|
|
903
898
|
* @returns {boolean} true if WebGL is supported
|
|
@@ -920,7 +915,7 @@ let device = {
|
|
|
920
915
|
|
|
921
916
|
/**
|
|
922
917
|
* return the highest precision format supported by this device for GL Shaders
|
|
923
|
-
* @function
|
|
918
|
+
* @function device.getMaxShaderPrecision
|
|
924
919
|
* @param {WebGLRenderingContext} gl
|
|
925
920
|
* @returns {boolean} "lowp", "mediump", or "highp"
|
|
926
921
|
*/
|
|
@@ -938,7 +933,7 @@ let device = {
|
|
|
938
933
|
|
|
939
934
|
/**
|
|
940
935
|
* Makes a request to bring this device window to the front.
|
|
941
|
-
* @function
|
|
936
|
+
* @function device.focus
|
|
942
937
|
* @example
|
|
943
938
|
* if (clicked) {
|
|
944
939
|
* me.device.focus();
|
|
@@ -974,65 +969,13 @@ let device = {
|
|
|
974
969
|
this.alpha = e.alpha;
|
|
975
970
|
},
|
|
976
971
|
|
|
977
|
-
/**
|
|
978
|
-
* Enters pointer lock, requesting it from the user first. Works on supported devices & browsers
|
|
979
|
-
* Must be called in a click event or an event that requires user interaction.
|
|
980
|
-
* If you need to run handle events for errors or change of the pointer lock, see below.
|
|
981
|
-
* @function me.device.turnOnPointerLock
|
|
982
|
-
* @example
|
|
983
|
-
* document.addEventListener("pointerlockchange", pointerlockchange, false);
|
|
984
|
-
* document.addEventListener("mozpointerlockchange", pointerlockchange, false);
|
|
985
|
-
* document.addEventListener("webkitpointerlockchange", pointerlockchange, false);
|
|
986
|
-
*
|
|
987
|
-
* document.addEventListener("pointerlockerror", pointerlockerror, false);
|
|
988
|
-
* document.addEventListener("mozpointerlockerror", pointerlockerror, false);
|
|
989
|
-
* document.addEventListener("webkitpointerlockerror", pointerlockerror, false);
|
|
990
|
-
*/
|
|
991
|
-
turnOnPointerLock() {
|
|
992
|
-
if (this.hasPointerLockSupport) {
|
|
993
|
-
var element = getParent();
|
|
994
|
-
if (this.ua.match(/Firefox/i)) {
|
|
995
|
-
var fullscreenchange = function() {
|
|
996
|
-
if ((prefixed("fullscreenElement", document) ||
|
|
997
|
-
document.mozFullScreenElement) === element) {
|
|
998
|
-
|
|
999
|
-
document.removeEventListener("fullscreenchange", fullscreenchange);
|
|
1000
|
-
document.removeEventListener("mozfullscreenchange", fullscreenchange);
|
|
1001
|
-
element.requestPointerLock = prefixed("requestPointerLock", element);
|
|
1002
|
-
element.requestPointerLock();
|
|
1003
|
-
}
|
|
1004
|
-
};
|
|
1005
|
-
|
|
1006
|
-
document.addEventListener("fullscreenchange", fullscreenchange, false);
|
|
1007
|
-
document.addEventListener("mozfullscreenchange", fullscreenchange, false);
|
|
1008
|
-
|
|
1009
|
-
this.requestFullscreen();
|
|
1010
|
-
|
|
1011
|
-
}
|
|
1012
|
-
else {
|
|
1013
|
-
element.requestPointerLock();
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
},
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Exits pointer lock. Works on supported devices & browsers
|
|
1020
|
-
* @function me.device.turnOffPointerLock
|
|
1021
|
-
* @function
|
|
1022
|
-
*/
|
|
1023
|
-
turnOffPointerLock() {
|
|
1024
|
-
if (this.hasPointerLockSupport) {
|
|
1025
|
-
document.exitPointerLock();
|
|
1026
|
-
}
|
|
1027
|
-
},
|
|
1028
|
-
|
|
1029
972
|
/**
|
|
1030
973
|
* Enable monitor of the device accelerator to detect the amount of physical force of acceleration the device is receiving.
|
|
1031
974
|
* (one some device a first user gesture will be required before calling this function)
|
|
1032
|
-
* @function
|
|
1033
|
-
* @see
|
|
1034
|
-
* @see
|
|
1035
|
-
* @see
|
|
975
|
+
* @function device.watchAccelerometer
|
|
976
|
+
* @see device.accelerationX
|
|
977
|
+
* @see device.accelerationY
|
|
978
|
+
* @see device.accelerationZ
|
|
1036
979
|
* @returns {boolean} false if not supported or permission not granted by the user
|
|
1037
980
|
* @example
|
|
1038
981
|
* // try to enable device accelerometer event on user gesture
|
|
@@ -1067,7 +1010,7 @@ let device = {
|
|
|
1067
1010
|
|
|
1068
1011
|
/**
|
|
1069
1012
|
* unwatch Accelerometor event
|
|
1070
|
-
* @function
|
|
1013
|
+
* @function device.unwatchAccelerometer
|
|
1071
1014
|
*/
|
|
1072
1015
|
unwatchAccelerometer() {
|
|
1073
1016
|
if (accelInitialized) {
|
|
@@ -1080,10 +1023,10 @@ let device = {
|
|
|
1080
1023
|
/**
|
|
1081
1024
|
* Enable monitor of the device orientation to detect the current orientation of the device as compared to the Earth coordinate frame.
|
|
1082
1025
|
* (one some device a first user gesture will be required before calling this function)
|
|
1083
|
-
* @function
|
|
1084
|
-
* @see
|
|
1085
|
-
* @see
|
|
1086
|
-
* @see
|
|
1026
|
+
* @function device.watchDeviceOrientation
|
|
1027
|
+
* @see device.alpha
|
|
1028
|
+
* @see device.beta
|
|
1029
|
+
* @see device.gamma
|
|
1087
1030
|
* @returns {boolean} false if not supported or permission not granted by the user
|
|
1088
1031
|
* @example
|
|
1089
1032
|
* // try to enable device orientation event on user gesture
|
|
@@ -1116,7 +1059,7 @@ let device = {
|
|
|
1116
1059
|
|
|
1117
1060
|
/**
|
|
1118
1061
|
* unwatch Device orientation event
|
|
1119
|
-
* @function
|
|
1062
|
+
* @function device.unwatchDeviceOrientation
|
|
1120
1063
|
*/
|
|
1121
1064
|
unwatchDeviceOrientation() {
|
|
1122
1065
|
if (deviceOrientationInitialized) {
|
|
@@ -1130,7 +1073,7 @@ let device = {
|
|
|
1130
1073
|
* If the device doesn't support vibration, this method has no effect. <br>
|
|
1131
1074
|
* If a vibration pattern is already in progress when this method is called,
|
|
1132
1075
|
* the previous pattern is halted and the new one begins instead.
|
|
1133
|
-
* @function
|
|
1076
|
+
* @function device.vibrate
|
|
1134
1077
|
* @param {number|number[]} pattern pattern of vibration and pause intervals
|
|
1135
1078
|
* @example
|
|
1136
1079
|
* // vibrate for 1000 ms
|
|
@@ -1153,7 +1096,7 @@ let device = {
|
|
|
1153
1096
|
/**
|
|
1154
1097
|
* Ratio of the resolution in physical pixels to the resolution in CSS pixels for the current display device.
|
|
1155
1098
|
* @name devicePixelRatio
|
|
1156
|
-
* @
|
|
1099
|
+
* @memberof device
|
|
1157
1100
|
* @public
|
|
1158
1101
|
* @type {number}
|
|
1159
1102
|
* @readonly
|
|
@@ -1171,7 +1114,7 @@ Object.defineProperty(device, "devicePixelRatio", {
|
|
|
1171
1114
|
/**
|
|
1172
1115
|
* Returns true if the browser/device is in full screen mode.
|
|
1173
1116
|
* @name isFullscreen
|
|
1174
|
-
* @
|
|
1117
|
+
* @memberof device
|
|
1175
1118
|
* @public
|
|
1176
1119
|
* @type {boolean}
|
|
1177
1120
|
* @readonly
|
|
@@ -1194,7 +1137,7 @@ Object.defineProperty(device, "isFullscreen", {
|
|
|
1194
1137
|
/**
|
|
1195
1138
|
* Returns true if the browser/device has audio capabilities.
|
|
1196
1139
|
* @name sound
|
|
1197
|
-
* @
|
|
1140
|
+
* @memberof device
|
|
1198
1141
|
* @public
|
|
1199
1142
|
* @type {boolean}
|
|
1200
1143
|
* @readonly
|