renderSpriteRotated method
void
renderSpriteRotated({})
The anchor determines the point around which the sprite is rotated
Implementation
void renderSpriteRotated({
required ui.Image image,
required double srcX,
required double srcY,
required double srcWidth,
required double srcHeight,
required double dstX,
required double dstY,
required double rotation,
double anchorX = 0.5,
double anchorY = 0.5,
double scale = 1.0,
int color = 1,
}){
final scos = cos(rotation) * scale;
final ssin = sin(rotation) * scale;
final width = -scos * anchorX + ssin * anchorY;
final height = -ssin * anchorX - scos * anchorY;
final tx = dstX + width;
final ty = dstY + height;
final scaledHeight = srcHeight * scale * anchorY;
final scaledWidth = srcWidth * scale * anchorX;
const piHalf = pi * 0.5;
final adjX = adj(rotation - piHalf, scaledHeight);
final adjY = opp(rotation - piHalf, scaledHeight);
final adjY2 = adj(rotation - piHalf, scaledWidth);
final adjX2 = opp(rotation - piHalf, scaledWidth);
bufferImage = image;
render(
color: color,
srcLeft: srcX,
srcTop: srcY,
srcRight: srcX + srcWidth,
srcBottom: srcY + srcHeight,
scale: cos(rotation) * scale,
rotation: sin(rotation) * scale,
dstX: tx + adjX2 + adjX,
dstY: ty - adjY2 + adjY,
);
}