diff --git a/CHANGELOG.md b/CHANGELOG.md index 6523dedbb..20d666d8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [next] - Updated the doc structure and minor language fixes - Adding AssetsCache.readBinaryFile +- Fix animations example ## 0.20.2 - Fix text component bug with anchor being applied twice diff --git a/docs/examples/animations/assets/images/creture.png b/docs/examples/animations/assets/images/creature.png similarity index 100% rename from docs/examples/animations/assets/images/creture.png rename to docs/examples/animations/assets/images/creature.png diff --git a/docs/examples/animations/lib/main.dart b/docs/examples/animations/lib/main.dart index 1b80c80b2..3a97a2b1d 100644 --- a/docs/examples/animations/lib/main.dart +++ b/docs/examples/animations/lib/main.dart @@ -10,32 +10,34 @@ void main() async { final Size size = await Flame.util.initialDimensions(); final game = MyGame(size); runApp(game.widget); - - Flame.util.addGestureRecognizer(TapGestureRecognizer() - ..onTapDown = (TapDownDetails evt) { - game.addAnimation(); - }); } class MyGame extends BaseGame { 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( - 291, 178, 'creture.png', 18, + 291, 178, 'creature.png', 18, amountPerRow: 10, - textureWidth: 291, - textureHeight: 178, + textureWidth: textureWidth, + textureHeight: textureHeight, stepTime: 0.15, - loop: false, + loop: true, destroyOnFinish: true); - animationComponent.x = (size.width - 291) / 2; - animationComponent.y = 250; + animationComponent.x = x - textureWidth / 2; + animationComponent.y = y - textureHeight / 2; add(animationComponent); } + @override + void onTapDown(TapDownDetails evt) { + addAnimation(evt.globalPosition.dx, evt.globalPosition.dy); + } + MyGame(Size screenSize) { size = screenSize; diff --git a/docs/examples/animations/pubspec.yaml b/docs/examples/animations/pubspec.yaml index 298ef3366..563ff9376 100644 --- a/docs/examples/animations/pubspec.yaml +++ b/docs/examples/animations/pubspec.yaml @@ -19,4 +19,4 @@ dev_dependencies: flutter: assets: - assets/images/chopper.png - - assets/images/creture.png + - assets/images/creature.png