Merge pull request #339 from spydon/fix-animations-example

Fix animations example
This commit is contained in:
Erick
2020-05-17 10:46:24 -03:00
committed by GitHub
4 changed files with 17 additions and 14 deletions

View File

@@ -3,6 +3,7 @@
## [next] ## [next]
- Updated the doc structure and minor language fixes - Updated the doc structure and minor language fixes
- Adding AssetsCache.readBinaryFile - Adding AssetsCache.readBinaryFile
- Fix animations example
## 0.20.2 ## 0.20.2
- Fix text component bug with anchor being applied twice - Fix text component bug with anchor being applied twice

View File

Before

Width:  |  Height:  |  Size: 92 KiB

After

Width:  |  Height:  |  Size: 92 KiB

View File

@@ -10,32 +10,34 @@ void main() async {
final Size size = await Flame.util.initialDimensions(); final Size size = await Flame.util.initialDimensions();
final game = MyGame(size); final game = MyGame(size);
runApp(game.widget); runApp(game.widget);
Flame.util.addGestureRecognizer(TapGestureRecognizer()
..onTapDown = (TapDownDetails evt) {
game.addAnimation();
});
} }
class MyGame extends BaseGame { class MyGame extends BaseGame {
final animation = flame_animation.Animation.sequenced('chopper.png', 4, final animation = flame_animation.Animation.sequenced('chopper.png', 4,
textureWidth: 48, textureHeight: 48, stepTime: 0.15); textureWidth: 48, textureHeight: 48, stepTime: 0.15, loop: true);
void addAnimation() { void addAnimation(double x, double y) {
const textureWidth = 291.0;
const textureHeight = 178.0;
final animationComponent = AnimationComponent.sequenced( final animationComponent = AnimationComponent.sequenced(
291, 178, 'creture.png', 18, 291, 178, 'creature.png', 18,
amountPerRow: 10, amountPerRow: 10,
textureWidth: 291, textureWidth: textureWidth,
textureHeight: 178, textureHeight: textureHeight,
stepTime: 0.15, stepTime: 0.15,
loop: false, loop: true,
destroyOnFinish: true); destroyOnFinish: true);
animationComponent.x = (size.width - 291) / 2; animationComponent.x = x - textureWidth / 2;
animationComponent.y = 250; animationComponent.y = y - textureHeight / 2;
add(animationComponent); add(animationComponent);
} }
@override
void onTapDown(TapDownDetails evt) {
addAnimation(evt.globalPosition.dx, evt.globalPosition.dy);
}
MyGame(Size screenSize) { MyGame(Size screenSize) {
size = screenSize; size = screenSize;

View File

@@ -19,4 +19,4 @@ dev_dependencies:
flutter: flutter:
assets: assets:
- assets/images/chopper.png - assets/images/chopper.png
- assets/images/creture.png - assets/images/creature.png