diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index a8849f33d5..ff03b2c7c0 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); diff --git a/packages/flame/test/_goldens/shadow3d_decorator_2.png b/packages/flame/test/_goldens/shadow3d_decorator_2.png index cc906b513c..f4ac453ddc 100644 Binary files a/packages/flame/test/_goldens/shadow3d_decorator_2.png and b/packages/flame/test/_goldens/shadow3d_decorator_2.png differ diff --git a/packages/flame/test/_goldens/shadow3d_decorator_3.png b/packages/flame/test/_goldens/shadow3d_decorator_3.png index c57f51f79b..07c127f593 100644 Binary files a/packages/flame/test/_goldens/shadow3d_decorator_3.png and b/packages/flame/test/_goldens/shadow3d_decorator_3.png differ diff --git a/packages/flame/test/rendering/shadow3d_decorator_test.dart b/packages/flame/test/rendering/shadow3d_decorator_test.dart index 6e587deade..24dc7c2ced 100644 --- a/packages/flame/test/rendering/shadow3d_decorator_test.dart +++ b/packages/flame/test/rendering/shadow3d_decorator_test.dart @@ -1,6 +1,7 @@ import 'dart:ui'; import 'package:flame/components.dart'; +import 'package:flame/palette.dart'; import 'package:flame/rendering.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -16,6 +17,7 @@ void main() { expect(decorator.yScale, 1.0); expect(decorator.blur, 0.0); expect(decorator.opacity, 0.6); + expect(decorator.baseColor, BasicPalette.black.color); }); testGolden( @@ -79,7 +81,8 @@ void main() { ..xShift = 250.0 ..yScale = 1.5 ..opacity = 0.4 - ..blur = 1.0, + ..blur = 1.0 + ..baseColor = BasicPalette.red.color, ), ]); },