Last active
April 19, 2020 16:47
-
-
Save fabtjar/bd2402ff0ba1e0bd81d5763a984dcb02 to your computer and use it in GitHub Desktop.
Gets the nearest object in a group from the given position
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public function getNearest(position:FlxPoint):FlxSprite { | |
| var closet = {obj: null, dist: 0.0} | |
| group.forEachAlive(obj -> { | |
| var dist = obj.getPosition().distanceTo(position); | |
| if (dist < closet.dist) { | |
| closet.obj = obj; | |
| closet.dist = dist; | |
| } | |
| }); | |
| return closet.obj; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment