@@ -57,12 +57,12 @@ let globalFloatingCounter = 0;
57
57
this . children = undefined ;
58
58
59
59
/**
60
- * The property of the child object that should be used to sort on <br>
60
+ * The property of the child object that should be used to sort on this container
61
61
* value : "x", "y", "z"
62
62
* @type {string }
63
- * @default me.game.sortOn
63
+ * @default "z"
64
64
*/
65
- this . sortOn = game . sortOn ;
65
+ this . sortOn = "z" ;
66
66
67
67
/**
68
68
* Specify if the children list should be automatically sorted when adding a new child
@@ -170,9 +170,9 @@ let globalFloatingCounter = 0;
170
170
* Add a child to the container <br>
171
171
* if auto-sort is disable, the object will be appended at the bottom of the list.
172
172
* Adding a child to the container will automatically remove it from its other container.
173
- * Meaning a child can only have one parent. This is important if you add a renderable
174
- * to a container then add it to the me.game.world container it will move it out of the
175
- * orginal container. Then when the me.game.world. reset() is called the renderable
173
+ * Meaning a child can only have one parent. This is important if you add a renderable
174
+ * to a container then add it to the World container it will move it out of the
175
+ * orginal container. Then when the World container reset() method is called the renderable
176
176
* will not be in any container. <br>
177
177
* if the given child implements a onActivateEvent method, that method will be called
178
178
* once the child is added to this container.
@@ -219,7 +219,7 @@ let globalFloatingCounter = 0;
219
219
220
220
// force repaint in case this is a static non-animated object
221
221
if ( this . isAttachedToRoot ( ) === true ) {
222
- game . repaint ( ) ;
222
+ this . isDirty = true ;
223
223
}
224
224
225
225
// force bounds update if required
@@ -229,7 +229,7 @@ let globalFloatingCounter = 0;
229
229
230
230
// if a physic body is defined, add it to the game world
231
231
if ( child . body instanceof Body ) {
232
- game . world . addBody ( child . body ) ;
232
+ this . getRootAncestor ( ) . addBody ( child . body ) ;
233
233
}
234
234
235
235
// triggered callback if defined
@@ -268,7 +268,7 @@ let globalFloatingCounter = 0;
268
268
269
269
// force repaint in case this is a static non-animated object
270
270
if ( this . isAttachedToRoot ( ) === true ) {
271
- game . repaint ( ) ;
271
+ this . isDirty = true ;
272
272
}
273
273
274
274
// force bounds update if required
@@ -278,7 +278,7 @@ let globalFloatingCounter = 0;
278
278
279
279
// if a physic body is defined, add it to the game world
280
280
if ( child . body instanceof Body ) {
281
- game . world . addBody ( child . body ) ;
281
+ this . getRootAncestor ( ) . addBody ( child . body ) ;
282
282
}
283
283
284
284
// triggered callback if defined
@@ -300,14 +300,14 @@ let globalFloatingCounter = 0;
300
300
* @param {Function } callback - fnction to execute on each element
301
301
* @param {object } [thisArg] - value to use as this(i.e reference Object) when executing callback.
302
302
* @example
303
- * // iterate through all children of the root container
304
- * me.game.world .forEach((child) => {
303
+ * // iterate through all children of this container
304
+ * container .forEach((child) => {
305
305
* // do something with the child
306
306
* child.doSomething();
307
307
* });
308
- * me.game.world .forEach((child, index) => { ... });
309
- * me.game.world .forEach((child, index, array) => { ... });
310
- * me.game.world .forEach((child, index, array) => { ... }, thisArg);
308
+ * container .forEach((child, index) => { ... });
309
+ * container .forEach((child, index, array) => { ... });
310
+ * container .forEach((child, index, array) => { ... }, thisArg);
311
311
*/
312
312
forEach ( callback , thisArg ) {
313
313
var context = this , i = 0 ;
@@ -411,15 +411,15 @@ let globalFloatingCounter = 0;
411
411
* var ent = myContainer.getChildByProp("name", "mainPlayer");
412
412
*
413
413
* // or query the whole world :
414
- * var ent = me.game.world .getChildByProp("name", "mainPlayer");
414
+ * var ent = container .getChildByProp("name", "mainPlayer");
415
415
*
416
416
* // partial property matches are also allowed by using a RegExp.
417
417
* // the following matches "redCOIN", "bluecoin", "bagOfCoins", etc :
418
- * var allCoins = me.game.world .getChildByProp("name", /coin/i);
418
+ * var allCoins = container .getChildByProp("name", /coin/i);
419
419
*
420
420
* // searching for numbers or other data types :
421
- * var zIndex10 = me.game.world .getChildByProp("z", 10);
422
- * var inViewport = me.game.world .getChildByProp("inViewport", true);
421
+ * var zIndex10 = container .getChildByProp("z", 10);
422
+ * var inViewport = container .getChildByProp("inViewport", true);
423
423
*/
424
424
getChildByProp ( prop , value ) {
425
425
var objList = [ ] ;
@@ -531,7 +531,6 @@ let globalFloatingCounter = 0;
531
531
532
532
/**
533
533
* Checks if this container is root or if it's attached to the root container.
534
- * @private
535
534
* @returns {boolean }
536
535
*/
537
536
isAttachedToRoot ( ) {
@@ -549,6 +548,25 @@ let globalFloatingCounter = 0;
549
548
}
550
549
}
551
550
551
+ /**
552
+ * Returns the instance of the root container (i.e. the current application World container).
553
+ * @returns {Container }
554
+ */
555
+ getRootAncestor ( ) {
556
+ if ( this . root === true ) {
557
+ return this ;
558
+ } else {
559
+ var ancestor = this . ancestor ;
560
+ while ( ancestor ) {
561
+ if ( ancestor . root === true ) {
562
+ break ;
563
+ }
564
+ ancestor = ancestor . ancestor ;
565
+ }
566
+ return ancestor ;
567
+ }
568
+ }
569
+
552
570
/**
553
571
* update the cointainer's bounding rect (private)
554
572
* @ignore
@@ -610,7 +628,7 @@ let globalFloatingCounter = 0;
610
628
// remove the body first to avoid a condition where a body can be detached
611
629
// from its parent, before the body is removed from the game world
612
630
if ( child . body instanceof Body ) {
613
- game . world . removeBody ( child . body ) ;
631
+ this . getRootAncestor ( ) . removeBody ( child . body ) ;
614
632
}
615
633
616
634
if ( ! keepalive ) {
@@ -633,7 +651,7 @@ let globalFloatingCounter = 0;
633
651
634
652
// force repaint in case this is a static non-animated object
635
653
if ( this . isAttachedToRoot ( ) === true ) {
636
- game . repaint ( ) ;
654
+ this . isDirty = true ;
637
655
}
638
656
639
657
// force bounds update if required
@@ -746,7 +764,7 @@ let globalFloatingCounter = 0;
746
764
// clear the defer id
747
765
this . pendingSort = null ;
748
766
// make sure we redraw everything
749
- game . repaint ( ) ;
767
+ this . isDirty = true ;
750
768
} , this ) ;
751
769
}
752
770
}
@@ -815,7 +833,7 @@ let globalFloatingCounter = 0;
815
833
816
834
/**
817
835
* container update function. <br>
818
- * automatically called by the game manager {@link game }
836
+ * automatically called by the application update loop {@link Application }
819
837
* @protected
820
838
* @param {number } dt - time since the last update in milliseconds.
821
839
* @returns {boolean } true if the Container is dirty
0 commit comments