@@ -1350,89 +1350,57 @@ var InputPlugin = new Class({
13501350
13511351 /**
13521352 * Return the child lowest down the display list (with the smallest index)
1353+ * Will iterate through all parent containers, if present.
13531354 *
13541355 * @method Phaser.Input.InputPlugin#sortHandlerGO
13551356 * @since 3.0.0
13561357 *
1357- * @param {Phaser.GameObjects.GameObject } childA - [description]
1358- * @param {Phaser.GameObjects.GameObject } childB - [description]
1358+ * @param {Phaser.GameObjects.GameObject } childA - The first Game Object to compare.
1359+ * @param {Phaser.GameObjects.GameObject } childB - The second Game Object to compare.
13591360 *
1360- * @return {integer } [description]
1361+ * @return {integer } Returns either a negative or positive integer, or zero if they match.
13611362 */
13621363 sortHandlerGO : function ( childA , childB )
13631364 {
1364- // The higher the index, the lower down the display list they are.
1365- // So entry 0 will be the top-most item (visually)
1366- var indexA = this . displayList . getIndex ( childA ) ;
1367- var indexB = this . displayList . getIndex ( childB ) ;
1368-
1369- if ( indexA < indexB )
1365+ if ( ! childA . parentContainer && ! childB . parentContainer )
13701366 {
1371- return 1 ;
1367+ // Quick bail out when neither child has a container
1368+ return this . displayList . getIndex ( childB ) - this . displayList . getIndex ( childA ) ;
13721369 }
1373- else if ( indexA > indexB )
1370+ else if ( childA . parentContainer === childB . parentContainer )
13741371 {
1375- return - 1 ;
1372+ // Quick bail out when both children have the same container
1373+ return childB . parentContainer . getIndex ( childB ) - childA . parentContainer . getIndex ( childA ) ;
13761374 }
1377-
1378- // Technically this shouldn't happen, but if the GO wasn't part of this display list then it'll
1379- // have an index of -1, so in some cases it can
1380- return 0 ;
1381- } ,
1382-
1383- /**
1384- * Return the child lowest down the display list (with the smallest index)
1385- *
1386- * @method Phaser.Input.InputPlugin#sortHandlerIO
1387- * @since 3.0.0
1388- *
1389- * @param {Phaser.Input.InteractiveObject } childA - [description]
1390- * @param {Phaser.Input.InteractiveObject } childB - [description]
1391- *
1392- * @return {integer } [description]
1393- */
1394- sortHandlerIO : function ( childA , childB )
1395- {
1396- // The higher the index, the lower down the display list they are.
1397- // So entry 0 will be the top-most item (visually)
1398- var indexA = this . displayList . getIndex ( childA . gameObject ) ;
1399- var indexB = this . displayList . getIndex ( childB . gameObject ) ;
1400-
1401- if ( indexA < indexB )
1402- {
1403- return 1 ;
1404- }
1405- else if ( indexA > indexB )
1375+ else
14061376 {
1407- return - 1 ;
1408- }
1377+ // Container index check
1378+ var listA = childA . getIndexList ( ) ;
1379+ var listB = childB . getIndexList ( ) ;
1380+ var len = Math . min ( listA . length , listB . length ) ;
14091381
1410- // Technically this shouldn't happen, but if the GO wasn't part of this display list then it'll
1411- // have an index of -1, so in some cases it can
1412- return 0 ;
1413- } ,
1382+ for ( var i = 0 ; i < len ; i ++ )
1383+ {
1384+ // var indexA = listA[i][0];
1385+ // var indexB = listB[i][0];
1386+ var indexA = listA [ i ] ;
1387+ var indexB = listB [ i ] ;
14141388
1415- /**
1416- * Given an array of Interactive Objects, sort the array and return it,
1417- * so that the objects are in index order with the lowest at the bottom.
1418- *
1419- * @method Phaser.Input.InputPlugin#sortInteractiveObjects
1420- * @since 3.0.0
1421- *
1422- * @param {Phaser.Input.InteractiveObject[] } interactiveObjects - [description]
1423- *
1424- * @return {Phaser.Input.InteractiveObject[] } [description]
1425- */
1426- sortInteractiveObjects : function ( interactiveObjects )
1427- {
1428- if ( interactiveObjects . length < 2 )
1429- {
1430- return interactiveObjects ;
1389+ if ( indexA === indexB )
1390+ {
1391+ // Go to the next level down
1392+ continue ;
1393+ }
1394+ else
1395+ {
1396+ // Non-matching parents, so return
1397+ return indexB - indexA ;
1398+ }
1399+ }
14311400 }
14321401
1433- this . scene . sys . depthSort ( ) ;
1434-
1435- return interactiveObjects . sort ( this . sortHandlerIO . bind ( this ) ) ;
1402+ // Technically this shouldn't happen, but ...
1403+ return 0 ;
14361404 } ,
14371405
14381406 /**
0 commit comments