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
|
@@ -19,20 +19,14 @@ var globalFloatingCounter = 0;
|
|
|
19
19
|
/**
|
|
20
20
|
* @classdesc
|
|
21
21
|
* me.Container represents a collection of child objects
|
|
22
|
-
* @
|
|
23
|
-
* @extends me.Renderable
|
|
24
|
-
* @memberOf me
|
|
25
|
-
* @constructor
|
|
26
|
-
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
27
|
-
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
28
|
-
* @param {number} [w=me.game.viewport.width] width of the container
|
|
29
|
-
* @param {number} [h=me.game.viewport.height] height of the container
|
|
22
|
+
* @augments Renderable
|
|
30
23
|
*/
|
|
31
|
-
|
|
32
24
|
class Container extends Renderable {
|
|
33
|
-
|
|
34
25
|
/**
|
|
35
|
-
* @
|
|
26
|
+
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
27
|
+
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
28
|
+
* @param {number} [width=game.viewport.width] width of the container
|
|
29
|
+
* @param {number} [height=game.viewport.height] height of the container
|
|
36
30
|
*/
|
|
37
31
|
constructor(x = 0, y = 0, width = game.viewport.width, height = game.viewport.height, root = false) {
|
|
38
32
|
|
|
@@ -51,7 +45,7 @@ class Container extends Renderable {
|
|
|
51
45
|
* @type {boolean}
|
|
52
46
|
* @default false
|
|
53
47
|
* @name root
|
|
54
|
-
* @
|
|
48
|
+
* @memberof Container
|
|
55
49
|
*/
|
|
56
50
|
this.root = root;
|
|
57
51
|
|
|
@@ -68,7 +62,7 @@ class Container extends Renderable {
|
|
|
68
62
|
* @type {string}
|
|
69
63
|
* @default me.game.sortOn
|
|
70
64
|
* @name sortOn
|
|
71
|
-
* @
|
|
65
|
+
* @memberof Container
|
|
72
66
|
*/
|
|
73
67
|
this.sortOn = game.sortOn;
|
|
74
68
|
|
|
@@ -78,7 +72,7 @@ class Container extends Renderable {
|
|
|
78
72
|
* @type {boolean}
|
|
79
73
|
* @default true
|
|
80
74
|
* @name autoSort
|
|
81
|
-
* @
|
|
75
|
+
* @memberof Container
|
|
82
76
|
*/
|
|
83
77
|
this.autoSort = true;
|
|
84
78
|
|
|
@@ -88,7 +82,7 @@ class Container extends Renderable {
|
|
|
88
82
|
* @type {boolean}
|
|
89
83
|
* @default true
|
|
90
84
|
* @name autoDepth
|
|
91
|
-
* @
|
|
85
|
+
* @memberof Container
|
|
92
86
|
*/
|
|
93
87
|
this.autoDepth = true;
|
|
94
88
|
|
|
@@ -98,14 +92,14 @@ class Container extends Renderable {
|
|
|
98
92
|
* @type {boolean}
|
|
99
93
|
* @default false
|
|
100
94
|
* @name clipping
|
|
101
|
-
* @
|
|
95
|
+
* @memberof Container
|
|
102
96
|
*/
|
|
103
97
|
this.clipping = false;
|
|
104
98
|
|
|
105
99
|
/**
|
|
106
100
|
* a callback to be extended, triggered after a child has been added or removed
|
|
107
101
|
* @name onChildChange
|
|
108
|
-
* @
|
|
102
|
+
* @memberof Container#
|
|
109
103
|
* @function
|
|
110
104
|
* @param {number} index added or removed child index
|
|
111
105
|
*/
|
|
@@ -121,10 +115,23 @@ class Container extends Renderable {
|
|
|
121
115
|
* @type {boolean}
|
|
122
116
|
* @default false
|
|
123
117
|
* @name enableChildBoundsUpdate
|
|
124
|
-
* @
|
|
118
|
+
* @memberof Container
|
|
125
119
|
*/
|
|
126
120
|
this.enableChildBoundsUpdate = false;
|
|
127
121
|
|
|
122
|
+
/**
|
|
123
|
+
* define a background color for this container
|
|
124
|
+
* @public
|
|
125
|
+
* @type {Color}
|
|
126
|
+
* @name backgroundColor
|
|
127
|
+
* @default (0, 0, 0, 0.0)
|
|
128
|
+
* @memberof Container
|
|
129
|
+
* @example
|
|
130
|
+
* // add a red background color to this container
|
|
131
|
+
* this.backgroundColor.setColor(255, 0, 0);
|
|
132
|
+
*/
|
|
133
|
+
this.backgroundColor = pool.pull("Color", 0, 0, 0, 0.0);
|
|
134
|
+
|
|
128
135
|
/**
|
|
129
136
|
* Used by the debug panel plugin
|
|
130
137
|
* @ignore
|
|
@@ -149,7 +156,7 @@ class Container extends Renderable {
|
|
|
149
156
|
/**
|
|
150
157
|
* reset the container, removing all childrens, and reseting transforms.
|
|
151
158
|
* @name reset
|
|
152
|
-
* @
|
|
159
|
+
* @memberof Container
|
|
153
160
|
* @function
|
|
154
161
|
*/
|
|
155
162
|
reset() {
|
|
@@ -172,6 +179,8 @@ class Container extends Renderable {
|
|
|
172
179
|
// just reset some variables
|
|
173
180
|
this.currentTransform.identity();
|
|
174
181
|
}
|
|
182
|
+
|
|
183
|
+
this.backgroundColor.setColor(0, 0, 0, 0.0);
|
|
175
184
|
}
|
|
176
185
|
|
|
177
186
|
/**
|
|
@@ -183,11 +192,11 @@ class Container extends Renderable {
|
|
|
183
192
|
* orginal container. Then when the me.game.world.reset() is called the renderable
|
|
184
193
|
* will not be in any container.
|
|
185
194
|
* @name addChild
|
|
186
|
-
* @
|
|
195
|
+
* @memberof Container.prototype
|
|
187
196
|
* @function
|
|
188
|
-
* @param {
|
|
197
|
+
* @param {Renderable} child
|
|
189
198
|
* @param {number} [z] forces the z index of the child to the specified value
|
|
190
|
-
* @returns {
|
|
199
|
+
* @returns {Renderable} the added child
|
|
191
200
|
*/
|
|
192
201
|
addChild(child, z) {
|
|
193
202
|
if (child.ancestor instanceof Container) {
|
|
@@ -247,11 +256,11 @@ class Container extends Renderable {
|
|
|
247
256
|
* Add a child to the container at the specified index<br>
|
|
248
257
|
* (the list won't be sorted after insertion)
|
|
249
258
|
* @name addChildAt
|
|
250
|
-
* @
|
|
259
|
+
* @memberof Container.prototype
|
|
251
260
|
* @function
|
|
252
|
-
* @param {
|
|
261
|
+
* @param {Renderable} child
|
|
253
262
|
* @param {number} index
|
|
254
|
-
* @returns {
|
|
263
|
+
* @returns {Renderable} the added child
|
|
255
264
|
*/
|
|
256
265
|
addChildAt(child, index) {
|
|
257
266
|
if (index >= 0 && index < this.getChildren().length) {
|
|
@@ -306,7 +315,7 @@ class Container extends Renderable {
|
|
|
306
315
|
* - The index of element in the array. <br>
|
|
307
316
|
* - The array forEach() was called upon. <br>
|
|
308
317
|
* @name forEach
|
|
309
|
-
* @
|
|
318
|
+
* @memberof Container.prototype
|
|
310
319
|
* @function
|
|
311
320
|
* @param {Function} callback fnction to execute on each element
|
|
312
321
|
* @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
|
|
@@ -343,10 +352,10 @@ class Container extends Renderable {
|
|
|
343
352
|
/**
|
|
344
353
|
* Swaps the position (z-index) of 2 children
|
|
345
354
|
* @name swapChildren
|
|
346
|
-
* @
|
|
355
|
+
* @memberof Container.prototype
|
|
347
356
|
* @function
|
|
348
|
-
* @param {
|
|
349
|
-
* @param {
|
|
357
|
+
* @param {Renderable} child
|
|
358
|
+
* @param {Renderable} child2
|
|
350
359
|
*/
|
|
351
360
|
swapChildren(child, child2) {
|
|
352
361
|
var index = this.getChildIndex(child);
|
|
@@ -369,10 +378,10 @@ class Container extends Renderable {
|
|
|
369
378
|
/**
|
|
370
379
|
* Returns the Child at the specified index
|
|
371
380
|
* @name getChildAt
|
|
372
|
-
* @
|
|
381
|
+
* @memberof Container.prototype
|
|
373
382
|
* @function
|
|
374
383
|
* @param {number} index
|
|
375
|
-
* @returns {
|
|
384
|
+
* @returns {Renderable} the child at the specified index
|
|
376
385
|
*/
|
|
377
386
|
getChildAt(index) {
|
|
378
387
|
if (index >= 0 && index < this.getChildren().length) {
|
|
@@ -386,9 +395,9 @@ class Container extends Renderable {
|
|
|
386
395
|
/**
|
|
387
396
|
* Returns the index of the given Child
|
|
388
397
|
* @name getChildIndex
|
|
389
|
-
* @
|
|
398
|
+
* @memberof Container.prototype
|
|
390
399
|
* @function
|
|
391
|
-
* @param {
|
|
400
|
+
* @param {Renderable} child
|
|
392
401
|
* @returns {number} index
|
|
393
402
|
*/
|
|
394
403
|
getChildIndex(child) {
|
|
@@ -398,10 +407,10 @@ class Container extends Renderable {
|
|
|
398
407
|
/**
|
|
399
408
|
* Returns the next child within the container or undefined if none
|
|
400
409
|
* @name getNextChild
|
|
401
|
-
* @
|
|
410
|
+
* @memberof Container
|
|
402
411
|
* @function
|
|
403
|
-
* @param {
|
|
404
|
-
* @returns {
|
|
412
|
+
* @param {Renderable} child
|
|
413
|
+
* @returns {Renderable} child
|
|
405
414
|
*/
|
|
406
415
|
getNextChild(child) {
|
|
407
416
|
var index = this.getChildren().indexOf(child) - 1;
|
|
@@ -414,9 +423,9 @@ class Container extends Renderable {
|
|
|
414
423
|
/**
|
|
415
424
|
* Returns true if contains the specified Child
|
|
416
425
|
* @name hasChild
|
|
417
|
-
* @
|
|
426
|
+
* @memberof Container.prototype
|
|
418
427
|
* @function
|
|
419
|
-
* @param {
|
|
428
|
+
* @param {Renderable} child
|
|
420
429
|
* @returns {boolean}
|
|
421
430
|
*/
|
|
422
431
|
hasChild(child) {
|
|
@@ -428,12 +437,12 @@ class Container extends Renderable {
|
|
|
428
437
|
* note : avoid calling this function every frame since
|
|
429
438
|
* it parses the whole object tree each time
|
|
430
439
|
* @name getChildByProp
|
|
431
|
-
* @
|
|
440
|
+
* @memberof Container.prototype
|
|
432
441
|
* @public
|
|
433
442
|
* @function
|
|
434
443
|
* @param {string} prop Property name
|
|
435
444
|
* @param {string|RegExp|number|boolean} value Value of the property
|
|
436
|
-
* @returns {
|
|
445
|
+
* @returns {Renderable[]} Array of childs
|
|
437
446
|
* @example
|
|
438
447
|
* // get the first child object called "mainPlayer" in a specific container :
|
|
439
448
|
* var ent = myContainer.getChildByProp("name", "mainPlayer");
|
|
@@ -480,11 +489,11 @@ class Container extends Renderable {
|
|
|
480
489
|
/**
|
|
481
490
|
* returns the list of childs with the specified class type
|
|
482
491
|
* @name getChildByType
|
|
483
|
-
* @
|
|
492
|
+
* @memberof Container.prototype
|
|
484
493
|
* @public
|
|
485
494
|
* @function
|
|
486
495
|
* @param {object} classType
|
|
487
|
-
* @returns {
|
|
496
|
+
* @returns {Renderable[]} Array of children
|
|
488
497
|
*/
|
|
489
498
|
getChildByType(classType) {
|
|
490
499
|
var objList = [];
|
|
@@ -507,11 +516,11 @@ class Container extends Renderable {
|
|
|
507
516
|
* note : avoid calling this function every frame since
|
|
508
517
|
* it parses the whole object list each time
|
|
509
518
|
* @name getChildByName
|
|
510
|
-
* @
|
|
519
|
+
* @memberof Container.prototype
|
|
511
520
|
* @public
|
|
512
521
|
* @function
|
|
513
522
|
* @param {string|RegExp|number|boolean} name child name
|
|
514
|
-
* @returns {
|
|
523
|
+
* @returns {Renderable[]} Array of children
|
|
515
524
|
*/
|
|
516
525
|
getChildByName(name) {
|
|
517
526
|
return this.getChildByProp("name", name);
|
|
@@ -522,11 +531,11 @@ class Container extends Renderable {
|
|
|
522
531
|
* note : avoid calling this function every frame since
|
|
523
532
|
* it parses the whole object list each time
|
|
524
533
|
* @name getChildByGUID
|
|
525
|
-
* @
|
|
534
|
+
* @memberof Container.prototype
|
|
526
535
|
* @public
|
|
527
536
|
* @function
|
|
528
537
|
* @param {string|RegExp|number|boolean} guid child GUID
|
|
529
|
-
* @returns {
|
|
538
|
+
* @returns {Renderable} corresponding child or null
|
|
530
539
|
*/
|
|
531
540
|
getChildByGUID(guid) {
|
|
532
541
|
var obj = this.getChildByProp("GUID", guid);
|
|
@@ -536,10 +545,10 @@ class Container extends Renderable {
|
|
|
536
545
|
/**
|
|
537
546
|
* return all child in this container
|
|
538
547
|
* @name getChildren
|
|
539
|
-
* @
|
|
548
|
+
* @memberof Container.prototype
|
|
540
549
|
* @public
|
|
541
550
|
* @function
|
|
542
|
-
* @returns {
|
|
551
|
+
* @returns {Renderable[]} an array of renderable object
|
|
543
552
|
*/
|
|
544
553
|
getChildren() {
|
|
545
554
|
if (typeof this.children === "undefined") {
|
|
@@ -552,9 +561,9 @@ class Container extends Renderable {
|
|
|
552
561
|
* update the bounding box for this shape.
|
|
553
562
|
* @ignore
|
|
554
563
|
* @name updateBounds
|
|
555
|
-
* @
|
|
564
|
+
* @memberof Renderable.prototype
|
|
556
565
|
* @function
|
|
557
|
-
* @returns {
|
|
566
|
+
* @returns {Bounds} this shape bounding box Rectangle object
|
|
558
567
|
*/
|
|
559
568
|
updateBounds(forceUpdateChildBounds = false) {
|
|
560
569
|
|
|
@@ -581,7 +590,7 @@ class Container extends Renderable {
|
|
|
581
590
|
* Checks if this container is root or if it's attached to the root container.
|
|
582
591
|
* @private
|
|
583
592
|
* @name isAttachedToRoot
|
|
584
|
-
* @
|
|
593
|
+
* @memberof Container.prototype
|
|
585
594
|
* @function
|
|
586
595
|
* @returns {boolean}
|
|
587
596
|
*/
|
|
@@ -604,7 +613,7 @@ class Container extends Renderable {
|
|
|
604
613
|
* update the cointainer's bounding rect (private)
|
|
605
614
|
* @ignore
|
|
606
615
|
* @name updateBoundsPos
|
|
607
|
-
* @
|
|
616
|
+
* @memberof Container.prototype
|
|
608
617
|
* @function
|
|
609
618
|
*/
|
|
610
619
|
updateBoundsPos(newX, newY) {
|
|
@@ -639,10 +648,10 @@ class Container extends Renderable {
|
|
|
639
648
|
/**
|
|
640
649
|
* Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
|
|
641
650
|
* @name removeChild
|
|
642
|
-
* @
|
|
651
|
+
* @memberof Container.prototype
|
|
643
652
|
* @public
|
|
644
653
|
* @function
|
|
645
|
-
* @param {
|
|
654
|
+
* @param {Renderable} child
|
|
646
655
|
* @param {boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
647
656
|
*/
|
|
648
657
|
removeChild(child, keepalive) {
|
|
@@ -657,11 +666,11 @@ class Container extends Renderable {
|
|
|
657
666
|
/**
|
|
658
667
|
* Removes (and optionally destroys) a child from the container.<br>
|
|
659
668
|
* (removal is immediate and unconditional)<br>
|
|
660
|
-
* Never use keepalive=true with objects from {@link
|
|
669
|
+
* Never use keepalive=true with objects from {@link pool}. Doing so will create a memory leak.
|
|
661
670
|
* @name removeChildNow
|
|
662
|
-
* @
|
|
671
|
+
* @memberof Container.prototype
|
|
663
672
|
* @function
|
|
664
|
-
* @param {
|
|
673
|
+
* @param {Renderable} child
|
|
665
674
|
* @param {boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
666
675
|
*/
|
|
667
676
|
removeChildNow(child, keepalive) {
|
|
@@ -712,7 +721,7 @@ class Container extends Renderable {
|
|
|
712
721
|
/**
|
|
713
722
|
* Automatically set the specified property of all childs to the given value
|
|
714
723
|
* @name setChildsProperty
|
|
715
|
-
* @
|
|
724
|
+
* @memberof Container.prototype
|
|
716
725
|
* @function
|
|
717
726
|
* @param {string} prop property name
|
|
718
727
|
* @param {object} value property value
|
|
@@ -730,9 +739,9 @@ class Container extends Renderable {
|
|
|
730
739
|
/**
|
|
731
740
|
* Move the child in the group one step forward (z depth).
|
|
732
741
|
* @name moveUp
|
|
733
|
-
* @
|
|
742
|
+
* @memberof Container.prototype
|
|
734
743
|
* @function
|
|
735
|
-
* @param {
|
|
744
|
+
* @param {Renderable} child
|
|
736
745
|
*/
|
|
737
746
|
moveUp(child) {
|
|
738
747
|
var childIndex = this.getChildIndex(child);
|
|
@@ -745,9 +754,9 @@ class Container extends Renderable {
|
|
|
745
754
|
/**
|
|
746
755
|
* Move the child in the group one step backward (z depth).
|
|
747
756
|
* @name moveDown
|
|
748
|
-
* @
|
|
757
|
+
* @memberof Container.prototype
|
|
749
758
|
* @function
|
|
750
|
-
* @param {
|
|
759
|
+
* @param {Renderable} child
|
|
751
760
|
*/
|
|
752
761
|
moveDown(child) {
|
|
753
762
|
var childIndex = this.getChildIndex(child);
|
|
@@ -760,9 +769,9 @@ class Container extends Renderable {
|
|
|
760
769
|
/**
|
|
761
770
|
* Move the specified child to the top(z depth).
|
|
762
771
|
* @name moveToTop
|
|
763
|
-
* @
|
|
772
|
+
* @memberof Container.prototype
|
|
764
773
|
* @function
|
|
765
|
-
* @param {
|
|
774
|
+
* @param {Renderable} child
|
|
766
775
|
*/
|
|
767
776
|
moveToTop(child) {
|
|
768
777
|
var childIndex = this.getChildIndex(child);
|
|
@@ -778,9 +787,9 @@ class Container extends Renderable {
|
|
|
778
787
|
/**
|
|
779
788
|
* Move the specified child the bottom (z depth).
|
|
780
789
|
* @name moveToBottom
|
|
781
|
-
* @
|
|
790
|
+
* @memberof Container.prototype
|
|
782
791
|
* @function
|
|
783
|
-
* @param {
|
|
792
|
+
* @param {Renderable} child
|
|
784
793
|
*/
|
|
785
794
|
moveToBottom(child) {
|
|
786
795
|
var childIndex = this.getChildIndex(child);
|
|
@@ -796,7 +805,7 @@ class Container extends Renderable {
|
|
|
796
805
|
/**
|
|
797
806
|
* Manually trigger the sort of all the childs in the container</p>
|
|
798
807
|
* @name sort
|
|
799
|
-
* @
|
|
808
|
+
* @memberof Container.prototype
|
|
800
809
|
* @public
|
|
801
810
|
* @function
|
|
802
811
|
* @param {boolean} [recursive=false] recursively sort all containers if true
|
|
@@ -889,9 +898,9 @@ class Container extends Renderable {
|
|
|
889
898
|
|
|
890
899
|
/**
|
|
891
900
|
* container update function. <br>
|
|
892
|
-
* automatically called by the game manager {@link
|
|
901
|
+
* automatically called by the game manager {@link game}
|
|
893
902
|
* @name update
|
|
894
|
-
* @
|
|
903
|
+
* @memberof Container.prototype
|
|
895
904
|
* @function
|
|
896
905
|
* @protected
|
|
897
906
|
* @param {number} dt time since the last update in milliseconds.
|
|
@@ -942,13 +951,13 @@ class Container extends Renderable {
|
|
|
942
951
|
|
|
943
952
|
/**
|
|
944
953
|
* draw the container. <br>
|
|
945
|
-
* automatically called by the game manager {@link
|
|
954
|
+
* automatically called by the game manager {@link game}
|
|
946
955
|
* @name draw
|
|
947
|
-
* @
|
|
956
|
+
* @memberof Container.prototype
|
|
948
957
|
* @function
|
|
949
958
|
* @protected
|
|
950
|
-
* @param {
|
|
951
|
-
* @param {
|
|
959
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
960
|
+
* @param {Rect|Bounds} [rect] the area or viewport to (re)draw
|
|
952
961
|
*/
|
|
953
962
|
draw(renderer, rect) {
|
|
954
963
|
var isFloating = false;
|
|
@@ -969,6 +978,11 @@ class Container extends Renderable {
|
|
|
969
978
|
// adjust position if required (e.g. canvas/window centering)
|
|
970
979
|
renderer.translate(this.pos.x, this.pos.y);
|
|
971
980
|
|
|
981
|
+
// color background if defined
|
|
982
|
+
if (this.backgroundColor.alpha > 1 / 255) {
|
|
983
|
+
renderer.clearColor(this.backgroundColor);
|
|
984
|
+
}
|
|
985
|
+
|
|
972
986
|
var children = this.getChildren();
|
|
973
987
|
for (var i = children.length, obj; i--, (obj = children[i]);) {
|
|
974
988
|
if (obj.isRenderable) {
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import Vector2d from "./../math/vector2.js";
|
|
2
|
+
import * as input from "./../input/input.js";
|
|
3
|
+
import * as event from "./../system/event.js";
|
|
4
|
+
import Renderable from "./../renderable/renderable.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @classdesc
|
|
8
|
+
* A Draggable base object
|
|
9
|
+
* @see DropTarget
|
|
10
|
+
* @augments Renderable
|
|
11
|
+
*/
|
|
12
|
+
export class Draggable extends Renderable {
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} x the x coordinates of the draggable object
|
|
15
|
+
* @param {number} y the y coordinates of the draggable object
|
|
16
|
+
* @param {number} width draggable object width
|
|
17
|
+
* @param {number} height draggable object height
|
|
18
|
+
*/
|
|
19
|
+
constructor(x, y, width, height) {
|
|
20
|
+
super(x, y, width, height);
|
|
21
|
+
this.isKinematic = false;
|
|
22
|
+
this.dragging = false;
|
|
23
|
+
this.dragId = null;
|
|
24
|
+
this.grabOffset = new Vector2d(0, 0);
|
|
25
|
+
this.initEvents();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Initializes the events the modules needs to listen to
|
|
30
|
+
* It translates the pointer events to me.events
|
|
31
|
+
* in order to make them pass through the system and to make
|
|
32
|
+
* this module testable. Then we subscribe this module to the
|
|
33
|
+
* transformed events.
|
|
34
|
+
* @name initEvents
|
|
35
|
+
* @memberof Draggable
|
|
36
|
+
* @function
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
initEvents() {
|
|
40
|
+
input.registerPointerEvent("pointerdown", this, (e) => { event.emit(event.DRAGSTART, e, this); });
|
|
41
|
+
input.registerPointerEvent("pointerup", this, (e) => { event.emit(event.DRAGEND, e, this); });
|
|
42
|
+
input.registerPointerEvent("pointercancel", this, (e) => { event.emit(event.DRAGEND, e, this); });
|
|
43
|
+
event.on(event.POINTERMOVE, this.dragMove.bind(this));
|
|
44
|
+
event.on(event.DRAGSTART, (e, draggable) => {
|
|
45
|
+
if (draggable === this) {
|
|
46
|
+
this.dragStart(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
event.on(event.DRAGEND, (e, draggable) => {
|
|
50
|
+
if (draggable === this) {
|
|
51
|
+
this.dragEnd(e);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Gets called when the user starts dragging the entity
|
|
58
|
+
* @name dragStart
|
|
59
|
+
* @memberof Draggable
|
|
60
|
+
* @function
|
|
61
|
+
* @param {object} e the pointer event
|
|
62
|
+
* @returns {boolean} false if the object is being dragged
|
|
63
|
+
*/
|
|
64
|
+
dragStart(e) {
|
|
65
|
+
if (this.dragging === false) {
|
|
66
|
+
this.dragging = true;
|
|
67
|
+
this.grabOffset.set(e.gameX, e.gameY);
|
|
68
|
+
this.grabOffset.sub(this.pos);
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets called when the user drags this entity around
|
|
75
|
+
* @name dragMove
|
|
76
|
+
* @memberof Draggable
|
|
77
|
+
* @function
|
|
78
|
+
* @param {object} e the pointer event
|
|
79
|
+
*/
|
|
80
|
+
dragMove(e) {
|
|
81
|
+
if (this.dragging === true) {
|
|
82
|
+
this.pos.set(e.gameX, e.gameY, this.pos.z); //TODO : z ?
|
|
83
|
+
this.pos.sub(this.grabOffset);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Gets called when the user stops dragging the entity
|
|
89
|
+
* @name dragEnd
|
|
90
|
+
* @memberof Draggable
|
|
91
|
+
* @function
|
|
92
|
+
* @returns {boolean} false if the object stopped being dragged
|
|
93
|
+
*/
|
|
94
|
+
dragEnd() {
|
|
95
|
+
if (this.dragging === true) {
|
|
96
|
+
this.dragging = false;
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Destructor
|
|
103
|
+
* @name destroy
|
|
104
|
+
* @memberof Draggable
|
|
105
|
+
* @function
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
destroy() {
|
|
109
|
+
event.off(event.POINTERMOVE, this.dragMove);
|
|
110
|
+
event.off(event.DRAGSTART, this.dragStart);
|
|
111
|
+
event.off(event.DRAGEND, this.dragEnd);
|
|
112
|
+
input.releasePointerEvent("pointerdown", this);
|
|
113
|
+
input.releasePointerEvent("pointerup", this);
|
|
114
|
+
input.releasePointerEvent("pointercancel", this);
|
|
115
|
+
super.destroy();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @classdesc
|
|
121
|
+
* a base drop target object
|
|
122
|
+
* @see Draggable
|
|
123
|
+
* @augments Renderable
|
|
124
|
+
*/
|
|
125
|
+
export class DropTarget extends Renderable {
|
|
126
|
+
/**
|
|
127
|
+
* @param {number} x the x coordinates of the drop target
|
|
128
|
+
* @param {number} y the y coordinates of the drop target
|
|
129
|
+
* @param {number} width drop target width
|
|
130
|
+
* @param {number} height drop target height
|
|
131
|
+
*/
|
|
132
|
+
constructor(x, y, width, height) {
|
|
133
|
+
super(x, y, width, height);
|
|
134
|
+
|
|
135
|
+
this.isKinematic = false;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* constant for the overlaps method
|
|
139
|
+
* @public
|
|
140
|
+
* @constant
|
|
141
|
+
* @type {string}
|
|
142
|
+
* @name CHECKMETHOD_OVERLAP
|
|
143
|
+
* @memberof DropTarget
|
|
144
|
+
*/
|
|
145
|
+
this.CHECKMETHOD_OVERLAP = "overlaps";
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* constant for the contains method
|
|
149
|
+
* @public
|
|
150
|
+
* @constant
|
|
151
|
+
* @type {string}
|
|
152
|
+
* @name CHECKMETHOD_CONTAINS
|
|
153
|
+
* @memberof DropTarget
|
|
154
|
+
*/
|
|
155
|
+
this.CHECKMETHOD_CONTAINS = "contains";
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* the checkmethod we want to use
|
|
159
|
+
* @public
|
|
160
|
+
* @constant
|
|
161
|
+
* @type {string}
|
|
162
|
+
* @name checkMethod
|
|
163
|
+
* @default "overlaps"
|
|
164
|
+
* @memberof DropTarget
|
|
165
|
+
*/
|
|
166
|
+
this.checkMethod = this.CHECKMETHOD_OVERLAP;
|
|
167
|
+
|
|
168
|
+
event.on(event.DRAGEND, this.checkOnMe, this);
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Sets the collision method which is going to be used to check a valid drop
|
|
174
|
+
* @name setCheckMethod
|
|
175
|
+
* @memberof DropTarget
|
|
176
|
+
* @function
|
|
177
|
+
* @param {string} checkMethod the checkmethod (defaults to CHECKMETHOD_OVERLAP)
|
|
178
|
+
*/
|
|
179
|
+
setCheckMethod(checkMethod) {
|
|
180
|
+
// We can improve this check,
|
|
181
|
+
// because now you can use every method in theory
|
|
182
|
+
if (typeof(this.getBounds()[this.checkMethod]) === "function") {
|
|
183
|
+
this.checkMethod = checkMethod;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Checks if a dropped entity is dropped on the current entity
|
|
189
|
+
* @name checkOnMe
|
|
190
|
+
* @memberof DropTarget
|
|
191
|
+
* @function
|
|
192
|
+
* @param {object} e the triggering event
|
|
193
|
+
* @param {Draggable} draggable the draggable object that is dropped
|
|
194
|
+
*/
|
|
195
|
+
checkOnMe(e, draggable) {
|
|
196
|
+
if (draggable && this.getBounds()[this.checkMethod](draggable.getBounds())) {
|
|
197
|
+
// call the drop method on the current entity
|
|
198
|
+
this.drop(draggable);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Gets called when a draggable entity is dropped on the current entity
|
|
204
|
+
* @name drop
|
|
205
|
+
* @memberof DropTarget
|
|
206
|
+
* @function
|
|
207
|
+
* @param {Draggable} draggable the draggable object that is dropped
|
|
208
|
+
*/
|
|
209
|
+
drop() {
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Destructor
|
|
215
|
+
* @name destroy
|
|
216
|
+
* @memberof DropTarget
|
|
217
|
+
* @function
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
destroy() {
|
|
221
|
+
event.off(event.DRAGEND, this.checkOnMe);
|
|
222
|
+
super.destroy();
|
|
223
|
+
}
|
|
224
|
+
};
|