getObjectsUnderPoint method

List<GDisplayObject> getObjectsUnderPoint(
  1. GPoint localPoint
)

Returns a list of display objects that are under the specified localPoint.

The list is sorted in such a way that the display object that is closest to the point is the first element.

The localPoint parameter is in the local coordinate system of the display object container.

If this display object container has a mask layer, display objects will be included in the returned list only if they are on the masked region.

If the recursive parameter is set to true, the function will also return display objects that are nested within other display objects under the localPoint.

If no display objects were hit, the returned list is empty.

Implementation

List<GDisplayObject> getObjectsUnderPoint(GPoint localPoint) {
  final result = <GDisplayObject>[];
  if (!$hasTouchableArea || !mouseEnabled || !hitTestMask(localPoint)) {
    return result;
  }
  final numChild = children.length;
  GDisplayObject? target;
  for (var i = numChild - 1; i >= 0; --i) {
    var child = children[i];
    if (child.isMask) continue;
    _sHitTestMatrix.copyFrom(child.transformationMatrix);
    _sHitTestMatrix.invert();
    _sHitTestMatrix.transformCoords(
      localPoint.x,
      localPoint.y,
      _sHitTestPoint,
    );
    if (child is GDisplayObjectContainer) {
      result.addAll(child.getObjectsUnderPoint(_sHitTestPoint));
    }
    target = child.hitTest(_sHitTestPoint);
    if (target != null) {
      result.add(child);
    }
  }
  return result;
}