Skip to content

Instantly share code, notes, and snippets.

@fabtjar
Last active April 19, 2020 16:47
Show Gist options
  • Select an option

  • Save fabtjar/bd2402ff0ba1e0bd81d5763a984dcb02 to your computer and use it in GitHub Desktop.

Select an option

Save fabtjar/bd2402ff0ba1e0bd81d5763a984dcb02 to your computer and use it in GitHub Desktop.
Gets the nearest object in a group from the given position
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