mirror of
https://github.com/flame-engine/flame.git
synced 2025-10-28 23:46:52 +08:00
Fix brighten and darken alpha issue. This is all thanks to @jtmcdole's insight & fixes [here](https://github.com/flame-engine/flame/pull/3407). --------- Co-authored-by: Lukas Klingsbo <lukas.klingsbo@gmail.com> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com> Co-authored-by: Lukas Klingsbo <me@lukas.fyi> Co-authored-by: John McDole <john@mcdole.org>
41 lines
1022 B
Dart
41 lines
1022 B
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/extensions.dart';
|
|
import 'package:flame/game.dart';
|
|
|
|
class ImageDarknessExample extends FlameGame {
|
|
ImageDarknessExample({
|
|
required this.darkness,
|
|
});
|
|
|
|
final double darkness;
|
|
|
|
static const String description = '''
|
|
Shows how a dart:ui `Image` can be darkened using Flame Image extensions.
|
|
Use the properties on the side to change the darkness of the image.
|
|
''';
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final image = await images.load('flame.png');
|
|
final darkenedImage = await image.darken(darkness / 100);
|
|
|
|
add(
|
|
SpriteComponent(
|
|
sprite: Sprite(image),
|
|
position: (size / 2) - Vector2(0, image.height / 2),
|
|
size: image.size,
|
|
anchor: Anchor.center,
|
|
),
|
|
);
|
|
|
|
add(
|
|
SpriteComponent(
|
|
sprite: Sprite(darkenedImage),
|
|
position: (size / 2) + Vector2(0, darkenedImage.height / 2),
|
|
size: image.size,
|
|
anchor: Anchor.center,
|
|
),
|
|
);
|
|
}
|
|
}
|