pointOffset method

Vector2? pointOffset(
  1. String name, {
  2. bool considerFlip = false,
})

Given a point name, returns the offset from the currKeyframe's origin to the matched point as identified in the animation document. This offset can be used attach Components to a SpriteComponent for complex animations or special effects.

If parent.isFlippedHorizontally is true, then the final value will have Vector2.x mulitplied by -1.

Likewise if parent.isFlippedVertically is true, then the final value will have Vector2.y mulitplied by -1.

Note that if considerFlip is true, then this offset will be calculated with respect to Keyframe.flipX and Keyframe.flipY values.

Implementation

Vector2? pointOffset(String name, {bool considerFlip = false}) {
  final Vector2? offset = currKeyframe?.data
      .pointOffset(point: name, considerFlip: considerFlip)
      ?.toVector2();

  if (offset == null) return null;

  return Vector2(
    switch (parent.isFlippedHorizontally) {
          true => -1,
          false => 1,
        } *
        offset.x,
    switch (parent.isFlippedVertically) {
          true => -1,
          false => 1,
        } *
        offset.y,
  );
}