hitTest method

  1. @override
ZKSprite? hitTest(
  1. dynamic touchX,
  2. dynamic touchY
)
override

Implementation

@override
ZKSprite? hitTest(touchX, touchY) {
  if (frame == null) return null;

  var a00 = matrix.a,
      a01 = matrix.c,
      a02 = matrix.tx,
      a10 = matrix.b,
      a11 = matrix.d,
      a12 = matrix.ty,
      id = 1 / (a00 * a11 + a01 * -a10);

  var x =
      a11 * id * touchX + -a01 * id * touchY + (a12 * a01 - a02 * a11) * id;
  var y =
      a00 * id * touchY + -a10 * id * touchX + (-a12 * a00 + a02 * a10) * id;

  if (MathUtil.inA2B(x, frame!.dstRect!.left, frame!.dstRect!.right) &&
      MathUtil.inA2B(y, frame!.dstRect!.top, frame!.dstRect!.bottom)) {
    return this;
  }

  return null;
}