getBlock method

Block getBlock(
  1. Vector2 p
)

Get which block's surface is at isometric position p.

This can be used to handle clicks or hovers. This is the opposite of getBlockCenterPosition.

Implementation

Block getBlock(Vector2 p) {
  final halfTile = _getBlockCache
    ..setFrom(effectiveTileSize)
    ..multiply(scale / 2);
  final multiplier = 1 - halfTile.y / (2 * effectiveTileHeight * scale.x);
  final iso = _getBlockIsoCache
    ..setFrom(p)
    ..sub(_offset)
    ..sub(position)
    ..translate(halfTile.x, halfTile.y * multiplier);
  final cart = isoToCart(iso);
  final px = (cart.x / halfTile.x - 1).ceil();
  final py = (cart.y / halfTile.y).ceil();
  return Block(px, py);
}