computeTransformation method
Computes the transformation parameters for rendering particles using this shape.
The method returns a tuple containing an ui.Image, a Rect, an RSTransform, and a Color. These parameters are used by the canvas to draw the particle in the desired shape and orientation.
particle
: The Particle instance containing properties such as size and position.defaultShapes
: The ui.Image representing default shape textures.
Returns a tuple (Image, Rect, RSTransform, Color)
with the computed parameters.
Implementation
@override
TransformationData? computeTransformation(
Particle particle,
ui.Image defaultShapes,
) {
final rect = Rect.fromLTWH(
0,
0,
Shape.defaultSpriteSize.width,
Shape.defaultSpriteSize.height,
);
final transform = RSTransform.fromComponents(
rotation: 0,
scale: min(
particle.size.width / Shape.defaultSpriteSize.width,
particle.size.height / Shape.defaultSpriteSize.height,
),
anchorX: Shape.defaultSpriteSize.width / 2,
anchorY: Shape.defaultSpriteSize.height / 2,
translateX: particle.position.dx,
translateY: particle.position.dy,
);
final color = particle.color;
return (image: defaultShapes, rect: rect, transform: transform, color: color, blendMode: null);
}