-
-
Notifications
You must be signed in to change notification settings - Fork 899
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adding ImageExtension.resize (#2418)
Adds a helper method to ImageExtension to make it easier to resize an image.
- Loading branch information
1 parent
1576bd8
commit a3f1601
Showing
6 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters