melonjs 9.1.0 → 10.0.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/{LICENSE → LICENSE.md} +0 -0
- package/README.md +93 -57
- package/dist/melonjs.js +10334 -11179
- package/dist/melonjs.min.js +4 -10
- package/dist/melonjs.module.d.ts +13206 -0
- package/dist/melonjs.module.js +9913 -10872
- package/package.json +19 -14
- package/src/audio/audio.js +477 -553
- package/src/camera/camera2d.js +67 -65
- package/src/entity/draggable.js +26 -35
- package/src/entity/droptarget.js +17 -14
- package/src/entity/entity.js +59 -79
- package/src/game.js +194 -204
- package/src/index.js +12 -30
- package/src/input/gamepad.js +8 -19
- package/src/input/keyboard.js +4 -4
- package/src/input/pointer.js +14 -12
- package/src/input/pointerevent.js +15 -13
- package/src/lang/deprecated.js +2 -887
- package/src/level/level.js +3 -3
- package/src/level/tiled/TMXGroup.js +7 -11
- package/src/level/tiled/TMXLayer.js +33 -32
- package/src/level/tiled/TMXTileMap.js +15 -19
- package/src/level/tiled/TMXTileset.js +5 -5
- package/src/level/tiled/TMXUtils.js +3 -3
- package/src/level/tiled/renderer/TMXRenderer.js +4 -0
- package/src/loader/loader.js +8 -23
- package/src/loader/loadingscreen.js +51 -60
- package/src/math/matrix3.js +1 -1
- package/src/particles/emitter.js +36 -39
- package/src/particles/particle.js +27 -12
- package/src/particles/particlecontainer.js +17 -16
- package/src/physics/body.js +80 -118
- package/src/physics/collision.js +5 -235
- package/src/physics/detector.js +235 -0
- package/src/physics/quadtree.js +14 -14
- package/src/physics/world.js +84 -18
- package/src/plugin/plugin.js +26 -24
- package/src/polyfill/console.js +9 -14
- package/src/renderable/GUI.js +48 -62
- package/src/renderable/collectable.js +11 -4
- package/src/renderable/colorlayer.js +28 -26
- package/src/renderable/container.js +120 -96
- package/src/renderable/imagelayer.js +94 -93
- package/src/renderable/renderable.js +164 -138
- package/src/renderable/sprite.js +42 -44
- package/src/renderable/trigger.js +24 -17
- package/src/shapes/ellipse.js +27 -27
- package/src/shapes/line.js +12 -8
- package/src/shapes/poly.js +77 -49
- package/src/shapes/rectangle.js +193 -268
- package/src/state/stage.js +23 -25
- package/src/state/state.js +35 -86
- package/src/system/device.js +233 -285
- package/src/system/event.js +485 -432
- package/src/system/pooling.js +61 -54
- package/src/system/save.js +17 -16
- package/src/system/timer.js +34 -38
- package/src/text/bitmaptext.js +44 -46
- package/src/text/text.js +39 -34
- package/src/tweens/easing.js +0 -2
- package/src/tweens/interpolation.js +3 -8
- package/src/tweens/tween.js +332 -351
- package/src/utils/function.js +6 -8
- package/src/utils/utils.js +34 -30
- package/src/video/canvas/canvas_renderer.js +13 -8
- package/src/video/renderer.js +8 -7
- package/src/video/texture.js +8 -8
- package/src/video/texture_cache.js +5 -5
- package/src/video/video.js +373 -403
- package/src/video/webgl/glshader.js +2 -2
- package/src/video/webgl/webgl_compositor.js +14 -8
- package/src/video/webgl/webgl_renderer.js +21 -19
- package/plugins/debug/debugPanel.js +0 -770
- package/plugins/debug/font/PressStart2P.fnt +0 -100
- package/plugins/debug/font/PressStart2P.ltr +0 -1
- package/plugins/debug/font/PressStart2P.png +0 -0
- package/plugins/debug/particleDebugPanel.js +0 -303
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import utils from "./../utils/utils.js";
|
|
2
|
-
import game from "./../game.js";
|
|
3
|
-
import event from "./../system/event.js";
|
|
2
|
+
import * as game from "./../game.js";
|
|
3
|
+
import * as event from "./../system/event.js";
|
|
4
4
|
import pool from "./../system/pooling.js";
|
|
5
5
|
import state from "./../state/state.js";
|
|
6
6
|
import Renderable from "./renderable.js";
|
|
7
|
+
import Body from "./../physics/body.js";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Private function to re-use for object removal in a defer
|
|
@@ -26,20 +27,23 @@ var globalFloatingCounter = 0;
|
|
|
26
27
|
* @param {Number} [w=me.game.viewport.width] width of the container
|
|
27
28
|
* @param {Number} [h=me.game.viewport.height] height of the container
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
class Container extends Renderable {
|
|
32
|
+
|
|
30
33
|
/**
|
|
31
34
|
* @ignore
|
|
32
35
|
*/
|
|
33
|
-
|
|
36
|
+
constructor(x = 0, y = 0, width = game.viewport.width, height = game.viewport.height, root = false) {
|
|
37
|
+
|
|
38
|
+
// call the super constructor
|
|
39
|
+
super(x, y, width, height);
|
|
40
|
+
|
|
34
41
|
/**
|
|
35
42
|
* keep track of pending sort
|
|
36
43
|
* @ignore
|
|
37
44
|
*/
|
|
38
45
|
this.pendingSort = null;
|
|
39
46
|
|
|
40
|
-
// call the _super constructor
|
|
41
|
-
this._super(Renderable, "init", [x, y, width, height]);
|
|
42
|
-
|
|
43
47
|
/**
|
|
44
48
|
* whether the container is the root of the scene
|
|
45
49
|
* @public
|
|
@@ -137,9 +141,9 @@ var Container = Renderable.extend({
|
|
|
137
141
|
// subscribe on the canvas resize event
|
|
138
142
|
if (this.root === true) {
|
|
139
143
|
// Workaround for not updating container child-bounds automatically (it's expensive!)
|
|
140
|
-
event.
|
|
144
|
+
event.on(event.CANVAS_ONRESIZE, this.updateBounds.bind(this, true));
|
|
141
145
|
}
|
|
142
|
-
}
|
|
146
|
+
}
|
|
143
147
|
|
|
144
148
|
/**
|
|
145
149
|
* reset the container, removing all childrens, and reseting transforms.
|
|
@@ -147,7 +151,7 @@ var Container = Renderable.extend({
|
|
|
147
151
|
* @memberOf me.Container
|
|
148
152
|
* @function
|
|
149
153
|
*/
|
|
150
|
-
reset
|
|
154
|
+
reset() {
|
|
151
155
|
// cancel any sort operation
|
|
152
156
|
if (this.pendingSort) {
|
|
153
157
|
clearTimeout(this.pendingSort);
|
|
@@ -167,8 +171,7 @@ var Container = Renderable.extend({
|
|
|
167
171
|
// just reset some variables
|
|
168
172
|
this.currentTransform.identity();
|
|
169
173
|
}
|
|
170
|
-
}
|
|
171
|
-
|
|
174
|
+
}
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
177
|
* Add a child to the container <br>
|
|
@@ -185,7 +188,7 @@ var Container = Renderable.extend({
|
|
|
185
188
|
* @param {number} [z] forces the z index of the child to the specified value
|
|
186
189
|
* @return {me.Renderable} the added child
|
|
187
190
|
*/
|
|
188
|
-
addChild
|
|
191
|
+
addChild(child, z) {
|
|
189
192
|
if (child.ancestor instanceof Container) {
|
|
190
193
|
child.ancestor.removeChildNow(child);
|
|
191
194
|
}
|
|
@@ -227,11 +230,17 @@ var Container = Renderable.extend({
|
|
|
227
230
|
if (this.enableChildBoundsUpdate) {
|
|
228
231
|
this.updateBounds(true);
|
|
229
232
|
}
|
|
233
|
+
|
|
234
|
+
// if a physic body is defined, add it to the game world
|
|
235
|
+
if (child.body instanceof Body) {
|
|
236
|
+
game.world.addBody(child.body);
|
|
237
|
+
}
|
|
238
|
+
|
|
230
239
|
// triggered callback if defined
|
|
231
240
|
this.onChildChange.call(this, this.getChildren().length - 1);
|
|
232
241
|
|
|
233
242
|
return child;
|
|
234
|
-
}
|
|
243
|
+
}
|
|
235
244
|
|
|
236
245
|
/**
|
|
237
246
|
* Add a child to the container at the specified index<br>
|
|
@@ -243,7 +252,7 @@ var Container = Renderable.extend({
|
|
|
243
252
|
* @param {Number} index
|
|
244
253
|
* @return {me.Renderable} the added child
|
|
245
254
|
*/
|
|
246
|
-
addChildAt
|
|
255
|
+
addChildAt(child, index) {
|
|
247
256
|
if (index >= 0 && index < this.getChildren().length) {
|
|
248
257
|
if (child.ancestor instanceof Container) {
|
|
249
258
|
child.ancestor.removeChildNow(child);
|
|
@@ -273,6 +282,12 @@ var Container = Renderable.extend({
|
|
|
273
282
|
if (this.enableChildBoundsUpdate) {
|
|
274
283
|
this.updateBounds(true);
|
|
275
284
|
}
|
|
285
|
+
|
|
286
|
+
// if a physic body is defined, add it to the game world
|
|
287
|
+
if (child.body instanceof Body) {
|
|
288
|
+
game.world.addBody(child.body);
|
|
289
|
+
}
|
|
290
|
+
|
|
276
291
|
// triggered callback if defined
|
|
277
292
|
this.onChildChange.call(this, index);
|
|
278
293
|
|
|
@@ -281,7 +296,7 @@ var Container = Renderable.extend({
|
|
|
281
296
|
else {
|
|
282
297
|
throw new Error("Index (" + index + ") Out Of Bounds for addChildAt()");
|
|
283
298
|
}
|
|
284
|
-
}
|
|
299
|
+
}
|
|
285
300
|
|
|
286
301
|
/**
|
|
287
302
|
* The forEach() method executes a provided function once per child element. <br>
|
|
@@ -304,7 +319,7 @@ var Container = Renderable.extend({
|
|
|
304
319
|
* me.game.world.forEach((child, index, array) => { ... });
|
|
305
320
|
* me.game.world.forEach((child, index, array) => { ... }, thisArg);
|
|
306
321
|
*/
|
|
307
|
-
forEach
|
|
322
|
+
forEach(callback, thisArg) {
|
|
308
323
|
var context = this, i = 0;
|
|
309
324
|
var children = this.getChildren();
|
|
310
325
|
|
|
@@ -322,7 +337,7 @@ var Container = Renderable.extend({
|
|
|
322
337
|
callback.call(context, children[i], i, children);
|
|
323
338
|
i++;
|
|
324
339
|
}
|
|
325
|
-
}
|
|
340
|
+
}
|
|
326
341
|
|
|
327
342
|
/**
|
|
328
343
|
* Swaps the position (z-index) of 2 children
|
|
@@ -332,7 +347,7 @@ var Container = Renderable.extend({
|
|
|
332
347
|
* @param {me.Renderable} child
|
|
333
348
|
* @param {me.Renderable} child2
|
|
334
349
|
*/
|
|
335
|
-
swapChildren
|
|
350
|
+
swapChildren(child, child2) {
|
|
336
351
|
var index = this.getChildIndex(child);
|
|
337
352
|
var index2 = this.getChildIndex(child2);
|
|
338
353
|
|
|
@@ -348,7 +363,7 @@ var Container = Renderable.extend({
|
|
|
348
363
|
else {
|
|
349
364
|
throw new Error(child + " Both the supplied childs must be a child of the caller " + this);
|
|
350
365
|
}
|
|
351
|
-
}
|
|
366
|
+
}
|
|
352
367
|
|
|
353
368
|
/**
|
|
354
369
|
* Returns the Child at the specified index
|
|
@@ -357,14 +372,14 @@ var Container = Renderable.extend({
|
|
|
357
372
|
* @function
|
|
358
373
|
* @param {Number} index
|
|
359
374
|
*/
|
|
360
|
-
getChildAt
|
|
375
|
+
getChildAt(index) {
|
|
361
376
|
if (index >= 0 && index < this.getChildren().length) {
|
|
362
377
|
return this.getChildren()[index];
|
|
363
378
|
}
|
|
364
379
|
else {
|
|
365
380
|
throw new Error("Index (" + index + ") Out Of Bounds for getChildAt()");
|
|
366
381
|
}
|
|
367
|
-
}
|
|
382
|
+
}
|
|
368
383
|
|
|
369
384
|
/**
|
|
370
385
|
* Returns the index of the given Child
|
|
@@ -373,9 +388,9 @@ var Container = Renderable.extend({
|
|
|
373
388
|
* @function
|
|
374
389
|
* @param {me.Renderable} child
|
|
375
390
|
*/
|
|
376
|
-
getChildIndex
|
|
391
|
+
getChildIndex(child) {
|
|
377
392
|
return this.getChildren().indexOf(child);
|
|
378
|
-
}
|
|
393
|
+
}
|
|
379
394
|
|
|
380
395
|
/**
|
|
381
396
|
* Returns the next child within the container or undefined if none
|
|
@@ -384,13 +399,13 @@ var Container = Renderable.extend({
|
|
|
384
399
|
* @function
|
|
385
400
|
* @param {me.Renderable} child
|
|
386
401
|
*/
|
|
387
|
-
getNextChild
|
|
402
|
+
getNextChild(child) {
|
|
388
403
|
var index = this.getChildren().indexOf(child) - 1;
|
|
389
404
|
if (index >= 0 && index < this.getChildren().length) {
|
|
390
405
|
return this.getChildAt(index);
|
|
391
406
|
}
|
|
392
407
|
return undefined;
|
|
393
|
-
}
|
|
408
|
+
}
|
|
394
409
|
|
|
395
410
|
/**
|
|
396
411
|
* Returns true if contains the specified Child
|
|
@@ -400,9 +415,9 @@ var Container = Renderable.extend({
|
|
|
400
415
|
* @param {me.Renderable} child
|
|
401
416
|
* @return {Boolean}
|
|
402
417
|
*/
|
|
403
|
-
hasChild
|
|
418
|
+
hasChild(child) {
|
|
404
419
|
return this === child.ancestor;
|
|
405
|
-
}
|
|
420
|
+
}
|
|
406
421
|
|
|
407
422
|
/**
|
|
408
423
|
* return the child corresponding to the given property and value.<br>
|
|
@@ -430,7 +445,7 @@ var Container = Renderable.extend({
|
|
|
430
445
|
* var zIndex10 = me.game.world.getChildByProp("z", 10);
|
|
431
446
|
* var inViewport = me.game.world.getChildByProp("inViewport", true);
|
|
432
447
|
*/
|
|
433
|
-
getChildByProp
|
|
448
|
+
getChildByProp(prop, value) {
|
|
434
449
|
var objList = [];
|
|
435
450
|
|
|
436
451
|
function compare(obj, prop) {
|
|
@@ -453,7 +468,7 @@ var Container = Renderable.extend({
|
|
|
453
468
|
});
|
|
454
469
|
|
|
455
470
|
return objList;
|
|
456
|
-
}
|
|
471
|
+
}
|
|
457
472
|
|
|
458
473
|
/**
|
|
459
474
|
* returns the list of childs with the specified class type
|
|
@@ -464,7 +479,7 @@ var Container = Renderable.extend({
|
|
|
464
479
|
* @param {Object} class type
|
|
465
480
|
* @return {me.Renderable[]} Array of children
|
|
466
481
|
*/
|
|
467
|
-
getChildByType
|
|
482
|
+
getChildByType(_class) {
|
|
468
483
|
var objList = [];
|
|
469
484
|
|
|
470
485
|
this.forEach((child) => {
|
|
@@ -477,7 +492,7 @@ var Container = Renderable.extend({
|
|
|
477
492
|
});
|
|
478
493
|
|
|
479
494
|
return objList;
|
|
480
|
-
}
|
|
495
|
+
}
|
|
481
496
|
|
|
482
497
|
/**
|
|
483
498
|
* returns the list of childs with the specified name<br>
|
|
@@ -491,9 +506,9 @@ var Container = Renderable.extend({
|
|
|
491
506
|
* @param {String|RegExp|Number|Boolean} name child name
|
|
492
507
|
* @return {me.Renderable[]} Array of children
|
|
493
508
|
*/
|
|
494
|
-
getChildByName
|
|
509
|
+
getChildByName(name) {
|
|
495
510
|
return this.getChildByProp("name", name);
|
|
496
|
-
}
|
|
511
|
+
}
|
|
497
512
|
|
|
498
513
|
/**
|
|
499
514
|
* return the child corresponding to the specified GUID<br>
|
|
@@ -506,10 +521,10 @@ var Container = Renderable.extend({
|
|
|
506
521
|
* @param {String|RegExp|Number|Boolean} GUID child GUID
|
|
507
522
|
* @return {me.Renderable} corresponding child or null
|
|
508
523
|
*/
|
|
509
|
-
getChildByGUID
|
|
524
|
+
getChildByGUID(guid) {
|
|
510
525
|
var obj = this.getChildByProp("GUID", guid);
|
|
511
526
|
return (obj.length > 0) ? obj[0] : null;
|
|
512
|
-
}
|
|
527
|
+
}
|
|
513
528
|
|
|
514
529
|
|
|
515
530
|
/**
|
|
@@ -521,12 +536,12 @@ var Container = Renderable.extend({
|
|
|
521
536
|
* @function
|
|
522
537
|
* @return {me.Renderable[]} an array of renderable object
|
|
523
538
|
*/
|
|
524
|
-
getChildren
|
|
539
|
+
getChildren() {
|
|
525
540
|
if (typeof this.children === "undefined") {
|
|
526
541
|
this.children = [];
|
|
527
542
|
}
|
|
528
543
|
return this.children;
|
|
529
|
-
}
|
|
544
|
+
}
|
|
530
545
|
|
|
531
546
|
/**
|
|
532
547
|
* update the bounding box for this shape.
|
|
@@ -536,9 +551,10 @@ var Container = Renderable.extend({
|
|
|
536
551
|
* @function
|
|
537
552
|
* @return {me.Bounds} this shape bounding box Rectangle object
|
|
538
553
|
*/
|
|
539
|
-
updateBounds
|
|
554
|
+
updateBounds(forceUpdateChildBounds = false) {
|
|
555
|
+
|
|
540
556
|
// call parent method
|
|
541
|
-
|
|
557
|
+
super.updateBounds();
|
|
542
558
|
|
|
543
559
|
var bounds = this.getBounds();
|
|
544
560
|
|
|
@@ -554,7 +570,7 @@ var Container = Renderable.extend({
|
|
|
554
570
|
}
|
|
555
571
|
|
|
556
572
|
return bounds;
|
|
557
|
-
}
|
|
573
|
+
}
|
|
558
574
|
|
|
559
575
|
/**
|
|
560
576
|
* Checks if this container is root or if it's attached to the root container.
|
|
@@ -564,7 +580,7 @@ var Container = Renderable.extend({
|
|
|
564
580
|
* @function
|
|
565
581
|
* @returns Boolean
|
|
566
582
|
*/
|
|
567
|
-
isAttachedToRoot
|
|
583
|
+
isAttachedToRoot() {
|
|
568
584
|
if (this.root === true) {
|
|
569
585
|
return true;
|
|
570
586
|
} else {
|
|
@@ -577,7 +593,7 @@ var Container = Renderable.extend({
|
|
|
577
593
|
}
|
|
578
594
|
return false;
|
|
579
595
|
}
|
|
580
|
-
}
|
|
596
|
+
}
|
|
581
597
|
|
|
582
598
|
/**
|
|
583
599
|
* update the cointainer's bounding rect (private)
|
|
@@ -586,8 +602,9 @@ var Container = Renderable.extend({
|
|
|
586
602
|
* @memberOf me.Container.prototype
|
|
587
603
|
* @function
|
|
588
604
|
*/
|
|
589
|
-
updateBoundsPos
|
|
590
|
-
|
|
605
|
+
updateBoundsPos(newX, newY) {
|
|
606
|
+
// call the parent method
|
|
607
|
+
super.updateBoundsPos(newX, newY);
|
|
591
608
|
|
|
592
609
|
// Notify children that the parent's position has changed
|
|
593
610
|
this.forEach((child) => {
|
|
@@ -601,18 +618,18 @@ var Container = Renderable.extend({
|
|
|
601
618
|
}
|
|
602
619
|
});
|
|
603
620
|
return this.getBounds();
|
|
604
|
-
}
|
|
621
|
+
}
|
|
605
622
|
|
|
606
623
|
/**
|
|
607
624
|
* @ignore
|
|
608
625
|
*/
|
|
609
|
-
onActivateEvent
|
|
626
|
+
onActivateEvent() {
|
|
610
627
|
this.forEach((child) => {
|
|
611
628
|
if (typeof child.onActivateEvent === "function") {
|
|
612
629
|
child.onActivateEvent();
|
|
613
630
|
}
|
|
614
631
|
});
|
|
615
|
-
}
|
|
632
|
+
}
|
|
616
633
|
|
|
617
634
|
/**
|
|
618
635
|
* Invokes the removeChildNow in a defer, to ensure the child is removed safely after the update & draw stack has completed
|
|
@@ -623,15 +640,14 @@ var Container = Renderable.extend({
|
|
|
623
640
|
* @param {me.Renderable} child
|
|
624
641
|
* @param {Boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
625
642
|
*/
|
|
626
|
-
removeChild
|
|
643
|
+
removeChild(child, keepalive) {
|
|
627
644
|
if (this.hasChild(child)) {
|
|
628
645
|
utils.function.defer(deferredRemove, this, child, keepalive);
|
|
629
646
|
}
|
|
630
647
|
else {
|
|
631
648
|
throw new Error("Child is not mine.");
|
|
632
649
|
}
|
|
633
|
-
}
|
|
634
|
-
|
|
650
|
+
}
|
|
635
651
|
|
|
636
652
|
/**
|
|
637
653
|
* Removes (and optionally destroys) a child from the container.<br>
|
|
@@ -643,18 +659,26 @@ var Container = Renderable.extend({
|
|
|
643
659
|
* @param {me.Renderable} child
|
|
644
660
|
* @param {Boolean} [keepalive=False] True to prevent calling child.destroy()
|
|
645
661
|
*/
|
|
646
|
-
removeChildNow
|
|
662
|
+
removeChildNow(child, keepalive) {
|
|
647
663
|
if (this.hasChild(child) && (this.getChildIndex(child) >= 0)) {
|
|
648
664
|
if (typeof child.onDeactivateEvent === "function") {
|
|
649
665
|
child.onDeactivateEvent();
|
|
650
666
|
}
|
|
651
667
|
|
|
668
|
+
// remove the body first to avoid a condition where a body can be detached
|
|
669
|
+
// from its parent, before the body is removed from the game world
|
|
670
|
+
if (child.body instanceof Body) {
|
|
671
|
+
game.world.removeBody(child.body);
|
|
672
|
+
}
|
|
673
|
+
|
|
652
674
|
if (!keepalive) {
|
|
653
|
-
|
|
654
|
-
|
|
675
|
+
// attempt at recycling the object
|
|
676
|
+
if (pool.push(child, false) === false ) {
|
|
677
|
+
// else just destroy it
|
|
678
|
+
if (typeof child.destroy === "function") {
|
|
679
|
+
child.destroy();
|
|
680
|
+
}
|
|
655
681
|
}
|
|
656
|
-
|
|
657
|
-
pool.push(child);
|
|
658
682
|
}
|
|
659
683
|
|
|
660
684
|
// Don't cache the child index; another element might have been removed
|
|
@@ -674,10 +698,11 @@ var Container = Renderable.extend({
|
|
|
674
698
|
if (this.enableChildBoundsUpdate) {
|
|
675
699
|
this.updateBounds(true);
|
|
676
700
|
}
|
|
701
|
+
|
|
677
702
|
// triggered callback if defined
|
|
678
703
|
this.onChildChange.call(this, childIndex);
|
|
679
704
|
}
|
|
680
|
-
}
|
|
705
|
+
}
|
|
681
706
|
|
|
682
707
|
/**
|
|
683
708
|
* Automatically set the specified property of all childs to the given value
|
|
@@ -688,14 +713,14 @@ var Container = Renderable.extend({
|
|
|
688
713
|
* @param {Object} value property value
|
|
689
714
|
* @param {Boolean} [recursive=false] recursively apply the value to child containers if true
|
|
690
715
|
*/
|
|
691
|
-
setChildsProperty
|
|
716
|
+
setChildsProperty(prop, val, recursive) {
|
|
692
717
|
this.forEach((child) => {
|
|
693
718
|
if ((recursive === true) && (child instanceof Container)) {
|
|
694
719
|
child.setChildsProperty(prop, val, recursive);
|
|
695
720
|
}
|
|
696
721
|
child[prop] = val;
|
|
697
722
|
});
|
|
698
|
-
}
|
|
723
|
+
}
|
|
699
724
|
|
|
700
725
|
/**
|
|
701
726
|
* Move the child in the group one step forward (z depth).
|
|
@@ -704,13 +729,13 @@ var Container = Renderable.extend({
|
|
|
704
729
|
* @function
|
|
705
730
|
* @param {me.Renderable} child
|
|
706
731
|
*/
|
|
707
|
-
moveUp
|
|
732
|
+
moveUp(child) {
|
|
708
733
|
var childIndex = this.getChildIndex(child);
|
|
709
734
|
if (childIndex - 1 >= 0) {
|
|
710
735
|
// note : we use an inverted loop
|
|
711
736
|
this.swapChildren(child, this.getChildAt(childIndex - 1));
|
|
712
737
|
}
|
|
713
|
-
}
|
|
738
|
+
}
|
|
714
739
|
|
|
715
740
|
/**
|
|
716
741
|
* Move the child in the group one step backward (z depth).
|
|
@@ -719,13 +744,13 @@ var Container = Renderable.extend({
|
|
|
719
744
|
* @function
|
|
720
745
|
* @param {me.Renderable} child
|
|
721
746
|
*/
|
|
722
|
-
moveDown
|
|
747
|
+
moveDown(child) {
|
|
723
748
|
var childIndex = this.getChildIndex(child);
|
|
724
749
|
if (childIndex >= 0 && (childIndex + 1) < this.getChildren().length) {
|
|
725
750
|
// note : we use an inverted loop
|
|
726
751
|
this.swapChildren(child, this.getChildAt(childIndex + 1));
|
|
727
752
|
}
|
|
728
|
-
}
|
|
753
|
+
}
|
|
729
754
|
|
|
730
755
|
/**
|
|
731
756
|
* Move the specified child to the top(z depth).
|
|
@@ -734,7 +759,7 @@ var Container = Renderable.extend({
|
|
|
734
759
|
* @function
|
|
735
760
|
* @param {me.Renderable} child
|
|
736
761
|
*/
|
|
737
|
-
moveToTop
|
|
762
|
+
moveToTop(child) {
|
|
738
763
|
var childIndex = this.getChildIndex(child);
|
|
739
764
|
if (childIndex > 0) {
|
|
740
765
|
var children = this.getChildren();
|
|
@@ -743,7 +768,7 @@ var Container = Renderable.extend({
|
|
|
743
768
|
// increment our child z value based on the previous child depth
|
|
744
769
|
child.pos.z = children[1].pos.z + 1;
|
|
745
770
|
}
|
|
746
|
-
}
|
|
771
|
+
}
|
|
747
772
|
|
|
748
773
|
/**
|
|
749
774
|
* Move the specified child the bottom (z depth).
|
|
@@ -752,7 +777,7 @@ var Container = Renderable.extend({
|
|
|
752
777
|
* @function
|
|
753
778
|
* @param {me.Renderable} child
|
|
754
779
|
*/
|
|
755
|
-
moveToBottom
|
|
780
|
+
moveToBottom(child) {
|
|
756
781
|
var childIndex = this.getChildIndex(child);
|
|
757
782
|
var children = this.getChildren();
|
|
758
783
|
if (childIndex >= 0 && childIndex < (children.length - 1)) {
|
|
@@ -761,7 +786,7 @@ var Container = Renderable.extend({
|
|
|
761
786
|
// increment our child z value based on the next child depth
|
|
762
787
|
child.pos.z = children[(children.length - 2)].pos.z - 1;
|
|
763
788
|
}
|
|
764
|
-
}
|
|
789
|
+
}
|
|
765
790
|
|
|
766
791
|
/**
|
|
767
792
|
* Manually trigger the sort of all the childs in the container</p>
|
|
@@ -771,7 +796,7 @@ var Container = Renderable.extend({
|
|
|
771
796
|
* @function
|
|
772
797
|
* @param {Boolean} [recursive=false] recursively sort all containers if true
|
|
773
798
|
*/
|
|
774
|
-
sort
|
|
799
|
+
sort(recursive) {
|
|
775
800
|
// do nothing if there is already a pending sort
|
|
776
801
|
if (!this.pendingSort) {
|
|
777
802
|
if (recursive === true) {
|
|
@@ -784,89 +809,87 @@ var Container = Renderable.extend({
|
|
|
784
809
|
});
|
|
785
810
|
}
|
|
786
811
|
/** @ignore */
|
|
787
|
-
this.pendingSort = utils.function.defer(function (
|
|
812
|
+
this.pendingSort = utils.function.defer(function () {
|
|
788
813
|
// sort everything in this container
|
|
789
|
-
|
|
814
|
+
this.getChildren().sort(this["_sort" + this.sortOn.toUpperCase()]);
|
|
790
815
|
// clear the defer id
|
|
791
|
-
|
|
816
|
+
this.pendingSort = null;
|
|
792
817
|
// make sure we redraw everything
|
|
793
818
|
game.repaint();
|
|
794
|
-
}, this
|
|
819
|
+
}, this);
|
|
795
820
|
}
|
|
796
|
-
}
|
|
821
|
+
}
|
|
797
822
|
|
|
798
823
|
/**
|
|
799
824
|
* @ignore
|
|
800
825
|
*/
|
|
801
|
-
onDeactivateEvent
|
|
826
|
+
onDeactivateEvent() {
|
|
802
827
|
this.forEach((child) => {
|
|
803
828
|
if (typeof child.onDeactivateEvent === "function") {
|
|
804
829
|
child.onDeactivateEvent();
|
|
805
830
|
}
|
|
806
831
|
});
|
|
807
|
-
}
|
|
832
|
+
}
|
|
808
833
|
|
|
809
834
|
/**
|
|
810
835
|
* Z Sorting function
|
|
811
836
|
* @ignore
|
|
812
837
|
*/
|
|
813
|
-
_sortZ
|
|
838
|
+
_sortZ(a, b) {
|
|
814
839
|
return (b.pos && a.pos) ? (b.pos.z - a.pos.z) : (a.pos ? -Infinity : Infinity);
|
|
815
|
-
}
|
|
840
|
+
}
|
|
816
841
|
|
|
817
842
|
/**
|
|
818
843
|
* Reverse Z Sorting function
|
|
819
844
|
* @ignore
|
|
820
845
|
*/
|
|
821
|
-
_sortReverseZ
|
|
846
|
+
_sortReverseZ(a, b) {
|
|
822
847
|
return (a.pos && b.pos) ? (a.pos.z - b.pos.z) : (a.pos ? Infinity : -Infinity);
|
|
823
|
-
}
|
|
848
|
+
}
|
|
824
849
|
|
|
825
850
|
/**
|
|
826
851
|
* X Sorting function
|
|
827
852
|
* @ignore
|
|
828
853
|
*/
|
|
829
|
-
_sortX
|
|
854
|
+
_sortX(a, b) {
|
|
830
855
|
if (!b.pos || !a.pos) {
|
|
831
856
|
return (a.pos ? -Infinity : Infinity);
|
|
832
857
|
}
|
|
833
858
|
var result = b.pos.z - a.pos.z;
|
|
834
859
|
return (result ? result : (b.pos.x - a.pos.x));
|
|
835
|
-
}
|
|
860
|
+
}
|
|
836
861
|
|
|
837
862
|
/**
|
|
838
863
|
* Y Sorting function
|
|
839
864
|
* @ignore
|
|
840
865
|
*/
|
|
841
|
-
_sortY
|
|
866
|
+
_sortY(a, b) {
|
|
842
867
|
if (!b.pos || !a.pos) {
|
|
843
868
|
return (a.pos ? -Infinity : Infinity);
|
|
844
869
|
}
|
|
845
870
|
var result = b.pos.z - a.pos.z;
|
|
846
871
|
return (result ? result : (b.pos.y - a.pos.y));
|
|
847
|
-
}
|
|
872
|
+
}
|
|
848
873
|
|
|
849
874
|
/**
|
|
850
875
|
* Destroy function<br>
|
|
851
876
|
* @ignore
|
|
852
877
|
*/
|
|
853
|
-
destroy
|
|
878
|
+
destroy() {
|
|
854
879
|
// empty the container
|
|
855
880
|
this.reset();
|
|
856
881
|
// call the parent destroy method
|
|
857
|
-
|
|
858
|
-
}
|
|
882
|
+
super.destroy(arguments);
|
|
883
|
+
}
|
|
859
884
|
|
|
860
885
|
/**
|
|
861
886
|
* @ignore
|
|
862
887
|
*/
|
|
863
|
-
update
|
|
864
|
-
this._super(Renderable, "update", [dt]);
|
|
865
|
-
var isDirty = false;
|
|
888
|
+
update(dt) {
|
|
866
889
|
var isFloating = false;
|
|
867
890
|
var isPaused = state.isPaused();
|
|
868
|
-
|
|
869
891
|
var children = this.getChildren();
|
|
892
|
+
|
|
870
893
|
for (var i = children.length, obj; i--, (obj = children[i]);) {
|
|
871
894
|
if (isPaused && (!obj.updateWhenPaused)) {
|
|
872
895
|
// skip this object
|
|
@@ -889,7 +912,7 @@ var Container = Renderable.extend({
|
|
|
889
912
|
});
|
|
890
913
|
|
|
891
914
|
// update our object
|
|
892
|
-
isDirty
|
|
915
|
+
this.isDirty |= ((obj.inViewport || obj.alwaysUpdate) && obj.update(dt));
|
|
893
916
|
|
|
894
917
|
if (globalFloatingCounter > 0) {
|
|
895
918
|
globalFloatingCounter--;
|
|
@@ -897,17 +920,18 @@ var Container = Renderable.extend({
|
|
|
897
920
|
}
|
|
898
921
|
else {
|
|
899
922
|
// just directly call update() for non renderable object
|
|
900
|
-
isDirty
|
|
923
|
+
this.isDirty |= obj.update(dt);
|
|
901
924
|
}
|
|
902
925
|
}
|
|
903
926
|
|
|
904
|
-
|
|
905
|
-
|
|
927
|
+
// call the parent method
|
|
928
|
+
return super.update(dt);
|
|
929
|
+
}
|
|
906
930
|
|
|
907
931
|
/**
|
|
908
932
|
* @ignore
|
|
909
933
|
*/
|
|
910
|
-
draw
|
|
934
|
+
draw(renderer, rect) {
|
|
911
935
|
var isFloating = false;
|
|
912
936
|
var bounds = this.getBounds();
|
|
913
937
|
|
|
@@ -959,6 +983,6 @@ var Container = Renderable.extend({
|
|
|
959
983
|
}
|
|
960
984
|
}
|
|
961
985
|
}
|
|
962
|
-
}
|
|
986
|
+
};
|
|
963
987
|
|
|
964
988
|
export default Container;
|