BarLifeComponent constructor

BarLifeComponent({
  1. required GameComponent target,
  2. Vector2? offset,
  3. BarLifeDrawPosition drawPosition = BarLifeDrawPosition.top,
  4. List<Color>? colors,
  5. TextStyle? textStyle,
  6. bool showLifeText = true,
  7. Color backgroundColor = const Color(0xFF000000),
  8. BorderRadius borderRadius = BorderRadius.zero,
  9. double borderWidth = 2,
  10. Color borderColor = const Color(0xFFFFFFFF),
  11. BarLifeTextBuilder? barLifeTextBuilder,
  12. double life = 100,
  13. double maxLife = 100,
  14. EdgeInsets? padding,
  15. Vector2? size,
})

Implementation

BarLifeComponent({
  required this.target,
  Vector2? offset,
  this.drawPosition = BarLifeDrawPosition.top,
  this.colors,
  this.textStyle,
  this.showLifeText = true,
  this.backgroundColor = const Color(0xFF000000),
  this.borderRadius = BorderRadius.zero,
  this.borderWidth = 2,
  this.borderColor = const Color(0xFFFFFFFF),
  this.barLifeTextBuilder,
  double life = 100,
  double maxLife = 100,
  EdgeInsets? padding,
  Vector2? size,
}) {
  _life = life;
  _maxLife = maxLife;
  _barLifeBorderPaint = _barLifeBorderPaint
    ..color = borderColor
    ..strokeWidth = borderWidth
    ..style = PaintingStyle.stroke;

  _barLifeBgPaint = _barLifeBgPaint
    ..color = backgroundColor
    ..style = PaintingStyle.fill;
  position = offset ?? Vector2.zero();

  _textConfig = TextPaint(
    style: textStyle ??
        TextStyle(
          fontSize: target.width * 0.2,
          color: Colors.white,
        ),
  );

  if (size != null) {
    this.size = size;
  } else {
    _textSize = _textConfig.getLineMetrics(_getLifeText()).size;
    final horizontal = _textSize.x * 0.2;
    this.padding = padding ??
        EdgeInsets.symmetric(
          horizontal: horizontal,
          vertical: horizontal / 2,
        );
    this.size = Vector2(
      _textSize.x + this.padding.horizontal,
      _textSize.y + this.padding.vertical,
    );
  }
}