render method
Implement this method to render the current game state in the canvas
.
Implementation
@override
void render(Canvas canvas) {
for (final entity in entities) {
final position = entity.get<PositionComponent>()!;
final size = entity.get<SizeComponent>()!.size;
final anchor = entity.get<AnchorComponent>()?.anchor ?? Anchor.topLeft;
final angle = entity.get<AngleComponent>()?.radians ?? 0;
final flip = entity.get<FlipComponent>();
canvas
..save()
..translate(position.x, position.y)
..rotate(angle);
final delta = -anchor.toVector2()
..multiply(size);
canvas.translate(delta.x, delta.y);
// Handle inverted rendering by moving center and flipping.
if (flip != null && (flip.flipX || flip.flipY)) {
canvas.translate(size.x / 2, size.y / 2);
canvas.scale(flip.flipX ? -1.0 : 1.0, flip.flipY ? -1.0 : 1.0);
canvas.translate(-size.x / 2, -size.y / 2);
}
renderEntity(canvas, entity);
canvas.restore();
}
}