sourceRect static method

Rect sourceRect(
  1. Sprite sprite, {
  2. double inset = sourceInset,
})

Source rectangle used to draw sprite.

Tiles cut from a tileset share their edges with the neighbouring cells. When the destination lands on a fractional pixel the sample on the edge can round into the next cell and paint a line of the neighbour's art, so the source is trimmed by half a texel. Sprites that occupy the whole image are returned untouched.

Implementation

static Rect sourceRect(Sprite sprite, {double inset = sourceInset}) {
  return insetSourceRect(
    Rect.fromLTWH(
      sprite.srcPosition.x,
      sprite.srcPosition.y,
      sprite.srcSize.x,
      sprite.srcSize.y,
    ),
    Rect.fromLTWH(
      0,
      0,
      sprite.image.width.toDouble(),
      sprite.image.height.toDouble(),
    ),
    inset: inset,
  );
}