convertPointToNodeSpace method

Offset convertPointToNodeSpace (
  1. Offset boxPoint
)

Converts a point from the coordinate system of the SpriteBox to the local coordinate system of the node.

This method is particularly useful when handling pointer events and need the pointers position in a local coordinate space.

Point localPoint = myNode.convertPointToNodeSpace(pointInBoxCoordinates);

Implementation

Offset convertPointToNodeSpace(Offset boxPoint) {
  assert(boxPoint != null);
  assert(_spriteBox != null);

  Vector4 v =_boxToNodeMatrix().transform(new Vector4(boxPoint.dx, boxPoint.dy, 0.0, 1.0));
  return new Offset(v[0], v[1]);
}