From c8d81aad3bb3206c3560def05ca0e8f5b66e95a1 Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Tue, 10 Dec 2024 11:41:39 -0500 Subject: [PATCH] More fixes --- .../lib/src/rendering/shadow3d_decorator.dart | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index a8849f33d50..ff03b2c7c0e 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -1,7 +1,8 @@ import 'dart:ui'; +import 'package:flame/src/palette.dart'; import 'package:flame/src/rendering/decorator.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math_64.dart' show Matrix4, Vector2; /// [Shadow3DDecorator] casts a realistic-looking shadow from the component /// onto the ground. @@ -24,13 +25,15 @@ class Shadow3DDecorator extends Decorator { double? yScale, double? blur, double? opacity, + Color? baseColor, }) : _base = base?.clone() ?? Vector2.zero(), _ascent = ascent ?? 0, _angle = angle ?? -1.4, _shift = xShift ?? 100.0, _scale = yScale ?? 1.0, _blur = blur ?? 0, - _opacity = opacity ?? 0.6; + _opacity = opacity ?? 0.6, + _baseColor = baseColor ?? BasicPalette.black.color; /// Coordinates of the point where the component "touches the ground". If the /// component is airborne (i.e. [ascent] is non-zero), then this should be the @@ -117,10 +120,18 @@ class Shadow3DDecorator extends Decorator { _paint = null; } + /// Shadow's base color before opacity. This defaults to pitch-black. + Color get baseColor => _baseColor; + Color _baseColor; + set baseColor(Color value) { + _baseColor = value; + _paint = null; + } + Paint? _paint; Paint _makePaint() { final paint = Paint(); - final color = Color.fromRGBO(0, 0, 0, opacity); + final color = baseColor.withOpacity(opacity); paint.colorFilter = ColorFilter.mode(color, BlendMode.srcIn); if (_blur > 0) { paint.imageFilter = ImageFilter.blur(sigmaX: blur, sigmaY: blur / _scale);