class NewComponent extends PositionComponent{
static final Color _color = Color(0xFFFFFFFF);
static final Paint _paint = Paint()
..color = _color
..style = PaintingStyle.fill;
Sprite? sprite;
Future<void> onLoad() async {
sprite = await Sprite.load('image.png');
}
@override
void render(Canvas canvas) {
super.render(canvas);
final double colorOpacity = opacity.clamp(0, 1.0);
_paint.color = _color.withOpacity(colorOpacity);
sprite?.render(
canvas,
size: size,
overridePaint: _paint,
);
}
}
透明度を動的に更新する際の重要事項
_paint.color = ? およびopacity.clamp(0, 1.0)