pub struct Sprite {
pub source: SourceRect,
pub color: Color,
pub transform: Affine2,
}Expand description
One piece of a sprite sheet, and where it goes.
The unit a batched sprite draw is built from. source is in texels of the
sheet, because that is how a sheet’s layout is known – a packer emits
pixel rectangles, and normalizing them at every call site is how one of
them eventually gets normalized twice. The quad is that rectangle’s size in
user units before the transform, so a sprite drawn with the identity lands
at its own size with its top-left corner at the origin.
Fields§
§source: SourceRectThe part of the sheet to draw, in texels.
color: ColorA color multiplied into this sprite alone.
White changes nothing, and is what Sprite::new and Sprite::at
give. This is what makes one sheet serve a whole palette – and it is
per sprite rather than per batch, which is the difference between one
draw and one draw per color.
transform: Affine2Where it goes, applied to a quad running from the origin to the source’s size.
A full affine rather than the rotation-scale-translation that
dart:ui restricts this to. That restriction buys a smaller per-sprite
payload for a shader that applies the transform itself; these are
applied here, where a general transform costs exactly the same and a
caller who wants to skew a sprite is not told they may not.