Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luanpotter committed Dec 10, 2024
1 parent c56610d commit c8d81aa
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/flame/lib/src/rendering/shadow3d_decorator.dart
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c8d81aa

Please sign in to comment.