@@ -364,7 +364,7 @@ var World = new Class({
364364 }
365365 else
366366 {
367- this . disableBody ( object [ i ] ) ;
367+ this . disableGameObjectBody ( object [ i ] ) ;
368368 }
369369 }
370370 }
@@ -375,21 +375,21 @@ var World = new Class({
375375 }
376376 else
377377 {
378- this . disableBody ( object ) ;
378+ this . disableGameObjectBody ( object ) ;
379379 }
380380 } ,
381381
382382 /**
383383 * [description]
384384 *
385- * @method Phaser.Physics.Arcade.World#disableBody
385+ * @method Phaser.Physics.Arcade.World#disableGameObjectBody
386386 * @since 3.0.0
387387 *
388388 * @param {Phaser.GameObjects.GameObject } object - [description]
389389 *
390390 * @return {Phaser.GameObjects.GameObject } [description]
391391 */
392- disableBody : function ( object )
392+ disableGameObjectBody : function ( object )
393393 {
394394 if ( object . body )
395395 {
@@ -403,13 +403,36 @@ var World = new Class({
403403 this . staticTree . remove ( object . body ) ;
404404 }
405405
406- object . body . destroy ( ) ;
407- object . body = null ;
406+ object . body . enable = false ;
408407 }
409408
410409 return object ;
411410 } ,
412411
412+ /**
413+ * [description]
414+ *
415+ * @method Phaser.Physics.Arcade.World#disableBody
416+ * @since 3.0.0
417+ *
418+ * @param {Phaser.Physics.Arcade.Body } body - [description]
419+ */
420+ disableBody : function ( body )
421+ {
422+ if ( body . physicsType === CONST . DYNAMIC_BODY )
423+ {
424+ this . tree . remove ( body ) ;
425+ this . bodies . delete ( body ) ;
426+ }
427+ else if ( body . physicsType === CONST . STATIC_BODY )
428+ {
429+ this . staticBodies . delete ( body ) ;
430+ this . staticTree . remove ( body ) ;
431+ }
432+
433+ body . enable = false ;
434+ } ,
435+
413436 /**
414437 * [description]
415438 *
@@ -662,6 +685,8 @@ var World = new Class({
662685 var bodies = this . bodies . entries ;
663686 var len = bodies . length ;
664687
688+ var toDestroy = [ ] ;
689+
665690 for ( i = 0 ; i < len ; i ++ )
666691 {
667692 body = bodies [ i ] ;
@@ -670,6 +695,11 @@ var World = new Class({
670695 {
671696 body . postUpdate ( ) ;
672697 }
698+
699+ if ( body . pendingDestroy )
700+ {
701+ toDestroy . push ( body ) ;
702+ }
673703 }
674704
675705 if ( this . drawDebug )
@@ -701,6 +731,15 @@ var World = new Class({
701731 }
702732 }
703733 }
734+
735+ for ( i = 0 ; i < toDestroy . length ; i ++ )
736+ {
737+ body = toDestroy [ i ] ;
738+
739+ this . emit ( 'destroybody' , this , body ) ;
740+
741+ body . destroy ( ) ;
742+ }
704743 } ,
705744
706745 /**
@@ -1403,13 +1442,13 @@ var World = new Class({
14031442 */
14041443 collideSpriteVsGroup : function ( sprite , group , collideCallback , processCallback , callbackContext , overlapOnly )
14051444 {
1406- if ( group . length === 0 )
1445+ var bodyA = sprite . body ;
1446+
1447+ if ( group . length === 0 || ! bodyA )
14071448 {
14081449 return ;
14091450 }
14101451
1411- var bodyA = sprite . body ;
1412-
14131452 // Does sprite collide with anything?
14141453
14151454 var minMax = this . treeMinMax ;
@@ -1608,6 +1647,13 @@ var World = new Class({
16081647 {
16091648 return ;
16101649 }
1650+
1651+ var children = group1 . getChildren ( ) ;
1652+
1653+ for ( var i = 0 ; i < children . length ; i ++ )
1654+ {
1655+ this . collideSpriteVsGroup ( children [ i ] , group2 , collideCallback , processCallback , callbackContext , overlapOnly ) ;
1656+ }
16111657 } ,
16121658
16131659 /**
@@ -1629,6 +1675,12 @@ var World = new Class({
16291675 */
16301676 destroy : function ( )
16311677 {
1678+ this . tree . clear ( ) ;
1679+ this . staticTree . clear ( ) ;
1680+ this . bodies . clear ( ) ;
1681+ this . staticBodies . clear ( ) ;
1682+ this . colliders . destroy ( ) ;
1683+
16321684 this . removeAllListeners ( ) ;
16331685 }
16341686
0 commit comments