BarLifeComponent constructor

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

Implementation

BarLifeComponent({
  required this.target,
  required Vector2 size,
  Vector2? offset,
  Vector2? textOffset,
  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,
}) {
  _life = life;
  _maxLife = maxLife;
  _textOffset = textOffset ?? _textOffset;
  _barLifeBorderPaint = _barLifeBorderPaint
    ..color = borderColor
    ..strokeWidth = borderWidth
    ..style = PaintingStyle.stroke;

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

  _textConfig = TextPaint(
    style: textStyle?.copyWith(fontSize: size.y * 0.8) ??
        TextStyle(fontSize: size.y * 0.8, color: Colors.white),
  );

  _textSize = _textConfig.getLineMetrics(_getLifeText()).size;
}