Files
flame/examples/lib/stories/image/brighten.dart
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
1.0 KiB
Dart

import 'package:flame/components.dart';
import 'package:flame/extensions.dart';
import 'package:flame/game.dart';
class ImageBrightnessExample extends FlameGame {
ImageBrightnessExample({
required this.brightness,
});
final double brightness;
static const String description = '''
Shows how a dart:ui `Image` can be brightened using Flame Image extensions.
Use the properties on the side to change the brightness of the image.
''';
@override
Future<void> onLoad() async {
final image = await images.load('flame.png');
final brightenedImage = await image.brighten(brightness / 100);
add(
SpriteComponent(
sprite: Sprite(image),
position: (size / 2) - Vector2(0, image.height / 2),
size: image.size,
anchor: Anchor.center,
),
);
add(
SpriteComponent(
sprite: Sprite(brightenedImage),
position: (size / 2) + Vector2(0, brightenedImage.height / 2),
size: image.size,
anchor: Anchor.center,
),
);
}
}