melonjs 10.3.0 → 10.5.1
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 +3147 -3293
- package/dist/melonjs.min.js +4 -4
- package/dist/melonjs.module.d.ts +3411 -3852
- package/dist/melonjs.module.js +3448 -3210
- package/package.json +18 -17
- package/src/audio/audio.js +29 -30
- package/src/camera/camera2d.js +46 -56
- package/src/entity/entity.js +30 -36
- package/src/game.js +21 -22
- package/src/geometries/ellipse.js +40 -46
- package/src/geometries/line.js +9 -11
- package/src/geometries/poly.js +53 -53
- package/src/geometries/rectangle.js +42 -44
- package/src/index.js +9 -26
- 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 +30 -31
- package/src/input/pointerevent.js +26 -26
- package/src/lang/deprecated.js +65 -6
- package/src/level/level.js +23 -24
- package/src/level/tiled/TMXGroup.js +7 -8
- package/src/level/tiled/TMXLayer.js +30 -32
- package/src/level/tiled/TMXObject.js +21 -21
- package/src/level/tiled/TMXTile.js +18 -18
- package/src/level/tiled/TMXTileMap.js +39 -44
- package/src/level/tiled/TMXTileset.js +12 -15
- package/src/level/tiled/TMXTilesetGroup.js +9 -9
- package/src/level/tiled/renderer/TMXHexagonalRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXIsometricRenderer.js +7 -8
- package/src/level/tiled/renderer/TMXOrthogonalRenderer.js +4 -5
- package/src/level/tiled/renderer/TMXRenderer.js +24 -25
- package/src/level/tiled/renderer/TMXStaggeredRenderer.js +1 -4
- package/src/loader/loader.js +14 -15
- package/src/loader/loadingscreen.js +2 -4
- package/src/math/color.js +47 -66
- package/src/math/math.js +15 -16
- package/src/math/matrix2.js +53 -58
- package/src/math/matrix3.js +56 -62
- package/src/math/observable_vector2.js +75 -76
- package/src/math/observable_vector3.js +79 -80
- package/src/math/vector2.js +91 -92
- package/src/math/vector3.js +94 -96
- package/src/particles/emitter.js +38 -40
- package/src/particles/particle.js +4 -5
- package/src/particles/particlecontainer.js +2 -3
- package/src/physics/body.js +46 -143
- package/src/physics/bounds.js +47 -47
- package/src/physics/collision.js +13 -14
- package/src/physics/detector.js +18 -17
- package/src/physics/quadtree.js +17 -19
- package/src/physics/sat.js +26 -26
- package/src/physics/world.js +24 -28
- package/src/plugin/plugin.js +11 -14
- package/src/renderable/GUI.js +41 -46
- package/src/renderable/collectable.js +4 -8
- package/src/renderable/colorlayer.js +6 -10
- package/src/renderable/container.js +87 -72
- package/src/renderable/dragndrop.js +224 -0
- package/src/renderable/imagelayer.js +25 -31
- package/src/renderable/nineslicesprite.js +41 -41
- package/src/renderable/renderable.js +114 -125
- package/src/renderable/sprite.js +62 -68
- package/src/renderable/trigger.js +25 -30
- package/src/state/stage.js +13 -17
- package/src/state/state.js +26 -27
- package/src/system/device.js +74 -75
- package/src/system/event.js +71 -72
- 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 -54
- package/src/text/bitmaptextdata.js +10 -10
- package/src/text/glyph.js +3 -0
- package/src/text/text.js +44 -49
- package/src/tweens/easing.js +1 -1
- package/src/tweens/interpolation.js +1 -1
- package/src/tweens/tween.js +43 -44
- 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 +58 -59
- package/src/video/renderer.js +49 -53
- package/src/video/texture.js +98 -111
- package/src/video/texture_cache.js +24 -6
- package/src/video/video.js +16 -17
- package/src/video/webgl/glshader.js +37 -38
- package/src/video/webgl/webgl_compositor.js +31 -32
- package/src/video/webgl/webgl_renderer.js +79 -80
- package/src/entity/draggable.js +0 -130
- package/src/entity/droptarget.js +0 -101
|
@@ -19,19 +19,14 @@ var globalFloatingCounter = 0;
|
|
|
19
19
|
/**
|
|
20
20
|
* @classdesc
|
|
21
21
|
* me.Container represents a collection of child objects
|
|
22
|
-
* @
|
|
23
|
-
* @augments me.Renderable
|
|
24
|
-
* @memberof me
|
|
25
|
-
* @param {number} [x=0] position of the container (accessible via the inherited pos.x property)
|
|
26
|
-
* @param {number} [y=0] position of the container (accessible via the inherited pos.y property)
|
|
27
|
-
* @param {number} [w=me.game.viewport.width] width of the container
|
|
28
|
-
* @param {number} [h=me.game.viewport.height] height of the container
|
|
22
|
+
* @augments Renderable
|
|
29
23
|
*/
|
|
30
|
-
|
|
31
24
|
class Container extends Renderable {
|
|
32
|
-
|
|
33
25
|
/**
|
|
34
|
-
* @
|
|
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
|
|
35
30
|
*/
|
|
36
31
|
constructor(x = 0, y = 0, width = game.viewport.width, height = game.viewport.height, root = false) {
|
|
37
32
|
|
|
@@ -50,7 +45,7 @@ class Container extends Renderable {
|
|
|
50
45
|
* @type {boolean}
|
|
51
46
|
* @default false
|
|
52
47
|
* @name root
|
|
53
|
-
* @memberof
|
|
48
|
+
* @memberof Container
|
|
54
49
|
*/
|
|
55
50
|
this.root = root;
|
|
56
51
|
|
|
@@ -67,7 +62,7 @@ class Container extends Renderable {
|
|
|
67
62
|
* @type {string}
|
|
68
63
|
* @default me.game.sortOn
|
|
69
64
|
* @name sortOn
|
|
70
|
-
* @memberof
|
|
65
|
+
* @memberof Container
|
|
71
66
|
*/
|
|
72
67
|
this.sortOn = game.sortOn;
|
|
73
68
|
|
|
@@ -77,7 +72,7 @@ class Container extends Renderable {
|
|
|
77
72
|
* @type {boolean}
|
|
78
73
|
* @default true
|
|
79
74
|
* @name autoSort
|
|
80
|
-
* @memberof
|
|
75
|
+
* @memberof Container
|
|
81
76
|
*/
|
|
82
77
|
this.autoSort = true;
|
|
83
78
|
|
|
@@ -87,7 +82,7 @@ class Container extends Renderable {
|
|
|
87
82
|
* @type {boolean}
|
|
88
83
|
* @default true
|
|
89
84
|
* @name autoDepth
|
|
90
|
-
* @memberof
|
|
85
|
+
* @memberof Container
|
|
91
86
|
*/
|
|
92
87
|
this.autoDepth = true;
|
|
93
88
|
|
|
@@ -97,14 +92,14 @@ class Container extends Renderable {
|
|
|
97
92
|
* @type {boolean}
|
|
98
93
|
* @default false
|
|
99
94
|
* @name clipping
|
|
100
|
-
* @memberof
|
|
95
|
+
* @memberof Container
|
|
101
96
|
*/
|
|
102
97
|
this.clipping = false;
|
|
103
98
|
|
|
104
99
|
/**
|
|
105
100
|
* a callback to be extended, triggered after a child has been added or removed
|
|
106
101
|
* @name onChildChange
|
|
107
|
-
* @memberof
|
|
102
|
+
* @memberof Container#
|
|
108
103
|
* @function
|
|
109
104
|
* @param {number} index added or removed child index
|
|
110
105
|
*/
|
|
@@ -120,10 +115,23 @@ class Container extends Renderable {
|
|
|
120
115
|
* @type {boolean}
|
|
121
116
|
* @default false
|
|
122
117
|
* @name enableChildBoundsUpdate
|
|
123
|
-
* @memberof
|
|
118
|
+
* @memberof Container
|
|
124
119
|
*/
|
|
125
120
|
this.enableChildBoundsUpdate = false;
|
|
126
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
|
+
|
|
127
135
|
/**
|
|
128
136
|
* Used by the debug panel plugin
|
|
129
137
|
* @ignore
|
|
@@ -148,7 +156,7 @@ class Container extends Renderable {
|
|
|
148
156
|
/**
|
|
149
157
|
* reset the container, removing all childrens, and reseting transforms.
|
|
150
158
|
* @name reset
|
|
151
|
-
* @memberof
|
|
159
|
+
* @memberof Container
|
|
152
160
|
* @function
|
|
153
161
|
*/
|
|
154
162
|
reset() {
|
|
@@ -171,6 +179,8 @@ class Container extends Renderable {
|
|
|
171
179
|
// just reset some variables
|
|
172
180
|
this.currentTransform.identity();
|
|
173
181
|
}
|
|
182
|
+
|
|
183
|
+
this.backgroundColor.setColor(0, 0, 0, 0.0);
|
|
174
184
|
}
|
|
175
185
|
|
|
176
186
|
/**
|
|
@@ -182,11 +192,11 @@ class Container extends Renderable {
|
|
|
182
192
|
* orginal container. Then when the me.game.world.reset() is called the renderable
|
|
183
193
|
* will not be in any container.
|
|
184
194
|
* @name addChild
|
|
185
|
-
* @memberof
|
|
195
|
+
* @memberof Container.prototype
|
|
186
196
|
* @function
|
|
187
|
-
* @param {
|
|
197
|
+
* @param {Renderable} child
|
|
188
198
|
* @param {number} [z] forces the z index of the child to the specified value
|
|
189
|
-
* @returns {
|
|
199
|
+
* @returns {Renderable} the added child
|
|
190
200
|
*/
|
|
191
201
|
addChild(child, z) {
|
|
192
202
|
if (child.ancestor instanceof Container) {
|
|
@@ -246,11 +256,11 @@ class Container extends Renderable {
|
|
|
246
256
|
* Add a child to the container at the specified index<br>
|
|
247
257
|
* (the list won't be sorted after insertion)
|
|
248
258
|
* @name addChildAt
|
|
249
|
-
* @memberof
|
|
259
|
+
* @memberof Container.prototype
|
|
250
260
|
* @function
|
|
251
|
-
* @param {
|
|
261
|
+
* @param {Renderable} child
|
|
252
262
|
* @param {number} index
|
|
253
|
-
* @returns {
|
|
263
|
+
* @returns {Renderable} the added child
|
|
254
264
|
*/
|
|
255
265
|
addChildAt(child, index) {
|
|
256
266
|
if (index >= 0 && index < this.getChildren().length) {
|
|
@@ -305,7 +315,7 @@ class Container extends Renderable {
|
|
|
305
315
|
* - The index of element in the array. <br>
|
|
306
316
|
* - The array forEach() was called upon. <br>
|
|
307
317
|
* @name forEach
|
|
308
|
-
* @memberof
|
|
318
|
+
* @memberof Container.prototype
|
|
309
319
|
* @function
|
|
310
320
|
* @param {Function} callback fnction to execute on each element
|
|
311
321
|
* @param {object} [thisArg] value to use as this(i.e reference Object) when executing callback.
|
|
@@ -342,10 +352,10 @@ class Container extends Renderable {
|
|
|
342
352
|
/**
|
|
343
353
|
* Swaps the position (z-index) of 2 children
|
|
344
354
|
* @name swapChildren
|
|
345
|
-
* @memberof
|
|
355
|
+
* @memberof Container.prototype
|
|
346
356
|
* @function
|
|
347
|
-
* @param {
|
|
348
|
-
* @param {
|
|
357
|
+
* @param {Renderable} child
|
|
358
|
+
* @param {Renderable} child2
|
|
349
359
|
*/
|
|
350
360
|
swapChildren(child, child2) {
|
|
351
361
|
var index = this.getChildIndex(child);
|
|
@@ -368,10 +378,10 @@ class Container extends Renderable {
|
|
|
368
378
|
/**
|
|
369
379
|
* Returns the Child at the specified index
|
|
370
380
|
* @name getChildAt
|
|
371
|
-
* @memberof
|
|
381
|
+
* @memberof Container.prototype
|
|
372
382
|
* @function
|
|
373
383
|
* @param {number} index
|
|
374
|
-
* @returns {
|
|
384
|
+
* @returns {Renderable} the child at the specified index
|
|
375
385
|
*/
|
|
376
386
|
getChildAt(index) {
|
|
377
387
|
if (index >= 0 && index < this.getChildren().length) {
|
|
@@ -385,9 +395,9 @@ class Container extends Renderable {
|
|
|
385
395
|
/**
|
|
386
396
|
* Returns the index of the given Child
|
|
387
397
|
* @name getChildIndex
|
|
388
|
-
* @memberof
|
|
398
|
+
* @memberof Container.prototype
|
|
389
399
|
* @function
|
|
390
|
-
* @param {
|
|
400
|
+
* @param {Renderable} child
|
|
391
401
|
* @returns {number} index
|
|
392
402
|
*/
|
|
393
403
|
getChildIndex(child) {
|
|
@@ -397,10 +407,10 @@ class Container extends Renderable {
|
|
|
397
407
|
/**
|
|
398
408
|
* Returns the next child within the container or undefined if none
|
|
399
409
|
* @name getNextChild
|
|
400
|
-
* @memberof
|
|
410
|
+
* @memberof Container
|
|
401
411
|
* @function
|
|
402
|
-
* @param {
|
|
403
|
-
* @returns {
|
|
412
|
+
* @param {Renderable} child
|
|
413
|
+
* @returns {Renderable} child
|
|
404
414
|
*/
|
|
405
415
|
getNextChild(child) {
|
|
406
416
|
var index = this.getChildren().indexOf(child) - 1;
|
|
@@ -413,9 +423,9 @@ class Container extends Renderable {
|
|
|
413
423
|
/**
|
|
414
424
|
* Returns true if contains the specified Child
|
|
415
425
|
* @name hasChild
|
|
416
|
-
* @memberof
|
|
426
|
+
* @memberof Container.prototype
|
|
417
427
|
* @function
|
|
418
|
-
* @param {
|
|
428
|
+
* @param {Renderable} child
|
|
419
429
|
* @returns {boolean}
|
|
420
430
|
*/
|
|
421
431
|
hasChild(child) {
|
|
@@ -427,12 +437,12 @@ class Container extends Renderable {
|
|
|
427
437
|
* note : avoid calling this function every frame since
|
|
428
438
|
* it parses the whole object tree each time
|
|
429
439
|
* @name getChildByProp
|
|
430
|
-
* @memberof
|
|
440
|
+
* @memberof Container.prototype
|
|
431
441
|
* @public
|
|
432
442
|
* @function
|
|
433
443
|
* @param {string} prop Property name
|
|
434
444
|
* @param {string|RegExp|number|boolean} value Value of the property
|
|
435
|
-
* @returns {
|
|
445
|
+
* @returns {Renderable[]} Array of childs
|
|
436
446
|
* @example
|
|
437
447
|
* // get the first child object called "mainPlayer" in a specific container :
|
|
438
448
|
* var ent = myContainer.getChildByProp("name", "mainPlayer");
|
|
@@ -479,11 +489,11 @@ class Container extends Renderable {
|
|
|
479
489
|
/**
|
|
480
490
|
* returns the list of childs with the specified class type
|
|
481
491
|
* @name getChildByType
|
|
482
|
-
* @memberof
|
|
492
|
+
* @memberof Container.prototype
|
|
483
493
|
* @public
|
|
484
494
|
* @function
|
|
485
495
|
* @param {object} classType
|
|
486
|
-
* @returns {
|
|
496
|
+
* @returns {Renderable[]} Array of children
|
|
487
497
|
*/
|
|
488
498
|
getChildByType(classType) {
|
|
489
499
|
var objList = [];
|
|
@@ -506,11 +516,11 @@ class Container extends Renderable {
|
|
|
506
516
|
* note : avoid calling this function every frame since
|
|
507
517
|
* it parses the whole object list each time
|
|
508
518
|
* @name getChildByName
|
|
509
|
-
* @memberof
|
|
519
|
+
* @memberof Container.prototype
|
|
510
520
|
* @public
|
|
511
521
|
* @function
|
|
512
522
|
* @param {string|RegExp|number|boolean} name child name
|
|
513
|
-
* @returns {
|
|
523
|
+
* @returns {Renderable[]} Array of children
|
|
514
524
|
*/
|
|
515
525
|
getChildByName(name) {
|
|
516
526
|
return this.getChildByProp("name", name);
|
|
@@ -521,11 +531,11 @@ class Container extends Renderable {
|
|
|
521
531
|
* note : avoid calling this function every frame since
|
|
522
532
|
* it parses the whole object list each time
|
|
523
533
|
* @name getChildByGUID
|
|
524
|
-
* @memberof
|
|
534
|
+
* @memberof Container.prototype
|
|
525
535
|
* @public
|
|
526
536
|
* @function
|
|
527
537
|
* @param {string|RegExp|number|boolean} guid child GUID
|
|
528
|
-
* @returns {
|
|
538
|
+
* @returns {Renderable} corresponding child or null
|
|
529
539
|
*/
|
|
530
540
|
getChildByGUID(guid) {
|
|
531
541
|
var obj = this.getChildByProp("GUID", guid);
|
|
@@ -535,10 +545,10 @@ class Container extends Renderable {
|
|
|
535
545
|
/**
|
|
536
546
|
* return all child in this container
|
|
537
547
|
* @name getChildren
|
|
538
|
-
* @memberof
|
|
548
|
+
* @memberof Container.prototype
|
|
539
549
|
* @public
|
|
540
550
|
* @function
|
|
541
|
-
* @returns {
|
|
551
|
+
* @returns {Renderable[]} an array of renderable object
|
|
542
552
|
*/
|
|
543
553
|
getChildren() {
|
|
544
554
|
if (typeof this.children === "undefined") {
|
|
@@ -551,9 +561,9 @@ class Container extends Renderable {
|
|
|
551
561
|
* update the bounding box for this shape.
|
|
552
562
|
* @ignore
|
|
553
563
|
* @name updateBounds
|
|
554
|
-
* @memberof
|
|
564
|
+
* @memberof Renderable.prototype
|
|
555
565
|
* @function
|
|
556
|
-
* @returns {
|
|
566
|
+
* @returns {Bounds} this shape bounding box Rectangle object
|
|
557
567
|
*/
|
|
558
568
|
updateBounds(forceUpdateChildBounds = false) {
|
|
559
569
|
|
|
@@ -580,7 +590,7 @@ class Container extends Renderable {
|
|
|
580
590
|
* Checks if this container is root or if it's attached to the root container.
|
|
581
591
|
* @private
|
|
582
592
|
* @name isAttachedToRoot
|
|
583
|
-
* @memberof
|
|
593
|
+
* @memberof Container.prototype
|
|
584
594
|
* @function
|
|
585
595
|
* @returns {boolean}
|
|
586
596
|
*/
|
|
@@ -603,7 +613,7 @@ class Container extends Renderable {
|
|
|
603
613
|
* update the cointainer's bounding rect (private)
|
|
604
614
|
* @ignore
|
|
605
615
|
* @name updateBoundsPos
|
|
606
|
-
* @memberof
|
|
616
|
+
* @memberof Container.prototype
|
|
607
617
|
* @function
|
|
608
618
|
*/
|
|
609
619
|
updateBoundsPos(newX, newY) {
|
|
@@ -638,10 +648,10 @@ class Container extends Renderable {
|
|
|
638
648
|
/**
|
|
639
649
|
* Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
|
|
640
650
|
* @name removeChild
|
|
641
|
-
* @memberof
|
|
651
|
+
* @memberof Container.prototype
|
|
642
652
|
* @public
|
|
643
653
|
* @function
|
|
644
|
-
* @param {
|
|
654
|
+
* @param {Renderable} child
|
|
645
655
|
* @param {boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
646
656
|
*/
|
|
647
657
|
removeChild(child, keepalive) {
|
|
@@ -656,11 +666,11 @@ class Container extends Renderable {
|
|
|
656
666
|
/**
|
|
657
667
|
* Removes (and optionally destroys) a child from the container.<br>
|
|
658
668
|
* (removal is immediate and unconditional)<br>
|
|
659
|
-
* 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.
|
|
660
670
|
* @name removeChildNow
|
|
661
|
-
* @memberof
|
|
671
|
+
* @memberof Container.prototype
|
|
662
672
|
* @function
|
|
663
|
-
* @param {
|
|
673
|
+
* @param {Renderable} child
|
|
664
674
|
* @param {boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
665
675
|
*/
|
|
666
676
|
removeChildNow(child, keepalive) {
|
|
@@ -711,7 +721,7 @@ class Container extends Renderable {
|
|
|
711
721
|
/**
|
|
712
722
|
* Automatically set the specified property of all childs to the given value
|
|
713
723
|
* @name setChildsProperty
|
|
714
|
-
* @memberof
|
|
724
|
+
* @memberof Container.prototype
|
|
715
725
|
* @function
|
|
716
726
|
* @param {string} prop property name
|
|
717
727
|
* @param {object} value property value
|
|
@@ -729,9 +739,9 @@ class Container extends Renderable {
|
|
|
729
739
|
/**
|
|
730
740
|
* Move the child in the group one step forward (z depth).
|
|
731
741
|
* @name moveUp
|
|
732
|
-
* @memberof
|
|
742
|
+
* @memberof Container.prototype
|
|
733
743
|
* @function
|
|
734
|
-
* @param {
|
|
744
|
+
* @param {Renderable} child
|
|
735
745
|
*/
|
|
736
746
|
moveUp(child) {
|
|
737
747
|
var childIndex = this.getChildIndex(child);
|
|
@@ -744,9 +754,9 @@ class Container extends Renderable {
|
|
|
744
754
|
/**
|
|
745
755
|
* Move the child in the group one step backward (z depth).
|
|
746
756
|
* @name moveDown
|
|
747
|
-
* @memberof
|
|
757
|
+
* @memberof Container.prototype
|
|
748
758
|
* @function
|
|
749
|
-
* @param {
|
|
759
|
+
* @param {Renderable} child
|
|
750
760
|
*/
|
|
751
761
|
moveDown(child) {
|
|
752
762
|
var childIndex = this.getChildIndex(child);
|
|
@@ -759,9 +769,9 @@ class Container extends Renderable {
|
|
|
759
769
|
/**
|
|
760
770
|
* Move the specified child to the top(z depth).
|
|
761
771
|
* @name moveToTop
|
|
762
|
-
* @memberof
|
|
772
|
+
* @memberof Container.prototype
|
|
763
773
|
* @function
|
|
764
|
-
* @param {
|
|
774
|
+
* @param {Renderable} child
|
|
765
775
|
*/
|
|
766
776
|
moveToTop(child) {
|
|
767
777
|
var childIndex = this.getChildIndex(child);
|
|
@@ -777,9 +787,9 @@ class Container extends Renderable {
|
|
|
777
787
|
/**
|
|
778
788
|
* Move the specified child the bottom (z depth).
|
|
779
789
|
* @name moveToBottom
|
|
780
|
-
* @memberof
|
|
790
|
+
* @memberof Container.prototype
|
|
781
791
|
* @function
|
|
782
|
-
* @param {
|
|
792
|
+
* @param {Renderable} child
|
|
783
793
|
*/
|
|
784
794
|
moveToBottom(child) {
|
|
785
795
|
var childIndex = this.getChildIndex(child);
|
|
@@ -795,7 +805,7 @@ class Container extends Renderable {
|
|
|
795
805
|
/**
|
|
796
806
|
* Manually trigger the sort of all the childs in the container</p>
|
|
797
807
|
* @name sort
|
|
798
|
-
* @memberof
|
|
808
|
+
* @memberof Container.prototype
|
|
799
809
|
* @public
|
|
800
810
|
* @function
|
|
801
811
|
* @param {boolean} [recursive=false] recursively sort all containers if true
|
|
@@ -888,9 +898,9 @@ class Container extends Renderable {
|
|
|
888
898
|
|
|
889
899
|
/**
|
|
890
900
|
* container update function. <br>
|
|
891
|
-
* automatically called by the game manager {@link
|
|
901
|
+
* automatically called by the game manager {@link game}
|
|
892
902
|
* @name update
|
|
893
|
-
* @memberof
|
|
903
|
+
* @memberof Container.prototype
|
|
894
904
|
* @function
|
|
895
905
|
* @protected
|
|
896
906
|
* @param {number} dt time since the last update in milliseconds.
|
|
@@ -941,13 +951,13 @@ class Container extends Renderable {
|
|
|
941
951
|
|
|
942
952
|
/**
|
|
943
953
|
* draw the container. <br>
|
|
944
|
-
* automatically called by the game manager {@link
|
|
954
|
+
* automatically called by the game manager {@link game}
|
|
945
955
|
* @name draw
|
|
946
|
-
* @memberof
|
|
956
|
+
* @memberof Container.prototype
|
|
947
957
|
* @function
|
|
948
958
|
* @protected
|
|
949
|
-
* @param {
|
|
950
|
-
* @param {
|
|
959
|
+
* @param {CanvasRenderer|WebGLRenderer} renderer a renderer object
|
|
960
|
+
* @param {Rect|Bounds} [rect] the area or viewport to (re)draw
|
|
951
961
|
*/
|
|
952
962
|
draw(renderer, rect) {
|
|
953
963
|
var isFloating = false;
|
|
@@ -968,6 +978,11 @@ class Container extends Renderable {
|
|
|
968
978
|
// adjust position if required (e.g. canvas/window centering)
|
|
969
979
|
renderer.translate(this.pos.x, this.pos.y);
|
|
970
980
|
|
|
981
|
+
// color background if defined
|
|
982
|
+
if (this.backgroundColor.alpha > 1 / 255) {
|
|
983
|
+
renderer.clearColor(this.backgroundColor);
|
|
984
|
+
}
|
|
985
|
+
|
|
971
986
|
var children = this.getChildren();
|
|
972
987
|
for (var i = children.length, obj; i--, (obj = children[i]);) {
|
|
973
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
|
+
* @ignore
|
|
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
|
+
* @ignore
|
|
219
|
+
*/
|
|
220
|
+
destroy() {
|
|
221
|
+
event.off(event.DRAGEND, this.checkOnMe);
|
|
222
|
+
super.destroy();
|
|
223
|
+
}
|
|
224
|
+
};
|