absoluteToLocal method

Vector2 absoluteToLocal(
  1. Vector2 point
)

Transform point from the global (world) coordinate space into the local coordinates. This function is the inverse of absolutePositionOf().

This can be used, for example, to detect whether a specific point on the screen lies within this PositionComponent, and where exactly it hits.

Implementation

Vector2 absoluteToLocal(Vector2 point) {
  var c = parent;
  while (c != null) {
    if (c is PositionComponent) {
      return toLocal(c.absoluteToLocal(point));
    }
    c = c.parent;
  }
  return toLocal(point);
}