BarLifeComponent constructor
BarLifeComponent({
- required GameComponent target,
- required Vector2 size,
- Vector2? offset,
- Vector2? textOffset,
- BarLifeDrawPosition drawPosition = BarLifeDrawPosition.top,
- List<
Color> ? colors, - TextStyle? textStyle,
- bool showLifeText = true,
- Color backgroundColor = const Color(0xFF000000),
- BorderRadius borderRadius = BorderRadius.zero,
- double borderWidth = 2,
- Color borderColor = const Color(0xFFFFFFFF),
- BarLifeTextBuilder? barLifeTextBuilder,
- double life = 100,
- 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;
}