feat: Adding ImageExtension.resize (#2418)

Adds a helper method to ImageExtension to make it easier to resize an image.
This commit is contained in:
Erick
2023-03-31 08:39:08 -03:00
committed by GitHub
parent 1576bd83a5
commit a3f1601db8
6 changed files with 96 additions and 2 deletions

View File

@ -0,0 +1,23 @@
import 'package:dashbook/dashbook.dart';
import 'package:examples/commons/commons.dart';
import 'package:examples/stories/image/resize.dart';
import 'package:flame/game.dart';
void addImageStories(Dashbook dashbook) {
dashbook.storiesOf('Image')
..decorator(CenterDecorator())
..add(
'resize',
(context) => GameWidget(
game: ImageResizeExample(
Vector2(
context.numberProperty('width', 200),
context.numberProperty('height', 300),
),
),
),
codeLink: baseLink('image/resize.dart'),
info: ImageResizeExample.description,
);
}

View File

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