@@ -624,8 +624,8 @@ var InputPlugin = new Class({
624624 // _temp contains a hit tested and camera culled list of IO objects
625625 this . _temp = this . hitTestPointer ( pointer ) ;
626626
627- this . sortGameObjects ( this . _temp ) ;
628- this . sortGameObjects ( this . _tempZones ) ;
627+ this . sortGameObjects ( this . _temp , pointer ) ;
628+ this . sortDropZones ( this . _tempZones ) ;
629629
630630 if ( this . topOnly )
631631 {
@@ -693,8 +693,8 @@ var InputPlugin = new Class({
693693 // _temp contains a hit tested and camera culled list of IO objects
694694 this . _temp = this . hitTestPointer ( pointer ) ;
695695
696- this . sortGameObjects ( this . _temp ) ;
697- this . sortGameObjects ( this . _tempZones ) ;
696+ this . sortGameObjects ( this . _temp , pointer ) ;
697+ this . sortDropZones ( this . _tempZones ) ;
698698
699699 if ( this . topOnly )
700700 {
@@ -1195,7 +1195,7 @@ var InputPlugin = new Class({
11951195 }
11961196 else if ( draglist . length > 1 )
11971197 {
1198- this . sortGameObjects ( draglist ) ;
1198+ this . sortGameObjects ( draglist , pointer ) ;
11991199
12001200 if ( this . topOnly )
12011201 {
@@ -1681,7 +1681,7 @@ var InputPlugin = new Class({
16811681
16821682 var aborted = false ;
16831683
1684- this . sortGameObjects ( previouslyOver ) ;
1684+ this . sortGameObjects ( previouslyOver , pointer ) ;
16851685
16861686 for ( var i = 0 ; i < total ; i ++ )
16871687 {
@@ -1807,7 +1807,7 @@ var InputPlugin = new Class({
18071807
18081808 if ( total > 0 )
18091809 {
1810- this . sortGameObjects ( justOut ) ;
1810+ this . sortGameObjects ( justOut , pointer ) ;
18111811
18121812 // Call onOut for everything in the justOut array
18131813 for ( i = 0 ; i < total ; i ++ )
@@ -1856,7 +1856,7 @@ var InputPlugin = new Class({
18561856
18571857 if ( total > 0 )
18581858 {
1859- this . sortGameObjects ( justOver ) ;
1859+ this . sortGameObjects ( justOver , pointer ) ;
18601860
18611861 // Call onOver for everything in the justOver array
18621862 for ( i = 0 ; i < total ; i ++ )
@@ -1900,7 +1900,7 @@ var InputPlugin = new Class({
19001900 previouslyOver = stillOver . concat ( justOver ) ;
19011901
19021902 // Then sort it into display list order
1903- this . _over [ pointer . id ] = this . sortGameObjects ( previouslyOver ) ;
1903+ this . _over [ pointer . id ] = this . sortGameObjects ( previouslyOver , pointer ) ;
19041904
19051905 return totalInteracted ;
19061906 } ,
@@ -2624,17 +2624,44 @@ var InputPlugin = new Class({
26242624 } ,
26252625
26262626 /**
2627- * Given an array of Game Objects, sort the array and return it, so that the objects are in depth index order
2628- * with the lowest at the bottom.
2627+ * Given an array of Game Objects and a Pointer , sort the array and return it,
2628+ * so that the objects are in render order with the lowest at the bottom.
26292629 *
26302630 * @method Phaser.Input.InputPlugin#sortGameObjects
26312631 * @since 3.0.0
26322632 *
26332633 * @param {Phaser.GameObjects.GameObject[] } gameObjects - An array of Game Objects to be sorted.
2634+ * @param {Phaser.Input.Pointer } pointer - The Pointer to check against the Game Objects.
2635+ *
2636+ * @return {Phaser.GameObjects.GameObject[] } The sorted array of Game Objects.
2637+ */
2638+ sortGameObjects : function ( gameObjects , pointer )
2639+ {
2640+ if ( gameObjects . length < 2 )
2641+ {
2642+ return gameObjects ;
2643+ }
2644+
2645+ var list = pointer . camera . renderList ;
2646+
2647+ return gameObjects . sort ( function ( childA , childB )
2648+ {
2649+ return list . indexOf ( childB ) - list . indexOf ( childA ) ;
2650+ } ) ;
2651+ } ,
2652+
2653+ /**
2654+ * Given an array of Drop Zone Game Objects, sort the array and return it,
2655+ * so that the objects are in depth index order with the lowest at the bottom.
2656+ *
2657+ * @method Phaser.Input.InputPlugin#sortDropZones
2658+ * @since 3.52.0
2659+ *
2660+ * @param {Phaser.GameObjects.GameObject[] } gameObjects - An array of Game Objects to be sorted.
26342661 *
26352662 * @return {Phaser.GameObjects.GameObject[] } The sorted array of Game Objects.
26362663 */
2637- sortGameObjects : function ( gameObjects )
2664+ sortDropZones : function ( gameObjects )
26382665 {
26392666 if ( gameObjects . length < 2 )
26402667 {
@@ -2643,23 +2670,25 @@ var InputPlugin = new Class({
26432670
26442671 this . scene . sys . depthSort ( ) ;
26452672
2646- return gameObjects . sort ( this . sortHandlerGO . bind ( this ) ) ;
2673+ return gameObjects . sort ( this . sortDropZoneHandler . bind ( this ) ) ;
26472674 } ,
26482675
26492676 /**
26502677 * Return the child lowest down the display list (with the smallest index)
26512678 * Will iterate through all parent containers, if present.
26522679 *
2653- * @method Phaser.Input.InputPlugin#sortHandlerGO
2680+ * Prior to version 3.52.0 this method was called `sortHandlerGO`.
2681+ *
2682+ * @method Phaser.Input.InputPlugin#sortDropZoneHandler
26542683 * @private
2655- * @since 3.0 .0
2684+ * @since 3.52 .0
26562685 *
26572686 * @param {Phaser.GameObjects.GameObject } childA - The first Game Object to compare.
26582687 * @param {Phaser.GameObjects.GameObject } childB - The second Game Object to compare.
26592688 *
26602689 * @return {number } Returns either a negative or positive integer, or zero if they match.
26612690 */
2662- sortHandlerGO : function ( childA , childB )
2691+ sortDropZoneHandler : function ( childA , childB )
26632692 {
26642693 if ( ! childA . parentContainer && ! childB . parentContainer )
26652694 {
0 commit comments