BarLifeComponent constructor
BarLifeComponent({
- required GameComponent target,
- Vector2? offset,
- 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,
- EdgeInsets? padding,
- 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,
);
}
}