Files
Luan Nico de8e3bcea2 fix: Fix brighten and darken alpha issue (#3414)
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>
2024-12-17 19:06:14 +01:00

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,
),
);
}
}