File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1975,6 +1975,60 @@ Phaser.Group.prototype.getBottom = function () {
19751975
19761976} ;
19771977
1978+ /**
1979+ * Get the closest child to given Object/Point/Sprite/Image
1980+ *
1981+ * @method Phaser.Group#getClosestTo
1982+ * @return {any } The child closest to given Object/Point/Sprite/Image
1983+ */
1984+ Phaser . Group . prototype . getClosestTo = function ( object ) {
1985+
1986+ if ( this . children . length !== 0 ) {
1987+ var distance = Number . MAX_VALUE ,
1988+ tempDistance = 0 ,
1989+ returnee ;
1990+ this . forEachAlive ( function ( e ) {
1991+
1992+ tempDistance = Math . abs ( Phaser . Point . distance ( object , e ) ) ;
1993+
1994+ if ( tempDistance < distance ) {
1995+ distance = tempDistance ;
1996+ returnee = e ;
1997+ }
1998+ } ) ;
1999+
2000+ if ( returnee ) return returnee ;
2001+ }
2002+
2003+ } ;
2004+
2005+ /**
2006+ * Get the farthest child to given Object/Point/Sprite/Image
2007+ *
2008+ * @method Phaser.Group#getFarthestFrom
2009+ * @return {any } The child farthest from given Object/Point/Sprite/Image
2010+ */
2011+ Phaser . Group . prototype . getFarthestFrom = function ( object ) {
2012+
2013+ if ( this . children . length !== 0 ) {
2014+ var distance = 0 ,
2015+ tempDistance = 0 ,
2016+ returnee ;
2017+ this . forEachAlive ( function ( e ) {
2018+
2019+ tempDistance = Math . abs ( Phaser . Point . distance ( object , e ) ) ;
2020+
2021+ if ( tempDistance > distance ) {
2022+ distance = tempDistance ;
2023+ returnee = e ;
2024+ }
2025+ } ) ;
2026+
2027+ if ( returnee ) return returnee ;
2028+ }
2029+
2030+ } ;
2031+
19782032/**
19792033* Get the number of living children in this group.
19802034*
You can’t perform that action at this time.
0 commit comments