From b2c88e31da573828461014d5d8c2247a7c3c4603 Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Sun, 2 Aug 2020 15:29:59 -0400 Subject: [PATCH 1/2] Fixes in examples --- doc/examples/animations/lib/main.dart | 41 ++++++++++++++++--------- doc/examples/aseprite/lib/main.dart | 4 ++- doc/examples/audiopool/lib/main.dart | 9 +++--- doc/examples/flare/lib/main.dart | 12 ++++---- doc/examples/go_desktop/lib/game.dart | 10 +++--- doc/examples/keyboard/lib/main.dart | 4 +-- doc/examples/parallax/lib/main.dart | 17 +++++----- doc/examples/render_flip/lib/main.dart | 9 ++++-- doc/examples/sound/lib/main.dart | 1 - doc/examples/tiled/lib/main.dart | 2 +- doc/examples/tiled/pubspec.yaml | 1 + lib/components/animation_component.dart | 18 ++++++++--- 12 files changed, 80 insertions(+), 48 deletions(-) diff --git a/doc/examples/animations/lib/main.dart b/doc/examples/animations/lib/main.dart index f343aa3c0..81500b7d8 100644 --- a/doc/examples/animations/lib/main.dart +++ b/doc/examples/animations/lib/main.dart @@ -8,26 +8,38 @@ import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); + await Flame.images.loadAll(['creture.png', 'chopper.png']); + final Size size = await Flame.util.initialDimensions(); final game = MyGame(size); runApp(game.widget); } class MyGame extends BaseGame with TapDetector { - final animation = flame_animation.Animation.sequenced('chopper.png', 4, - textureWidth: 48, textureHeight: 48, stepTime: 0.15, loop: true); + final animation = flame_animation.Animation.sequenced( + 'chopper.png', + 4, + textureWidth: 48, + textureHeight: 48, + stepTime: 0.15, + loop: true, + ); void addAnimation(double x, double y) { const textureWidth = 291.0; const textureHeight = 178.0; final animationComponent = AnimationComponent.sequenced( - 291, 178, 'creature.png', 18, - amountPerRow: 10, - textureWidth: textureWidth, - textureHeight: textureHeight, - stepTime: 0.15, - loop: true, - destroyOnFinish: true); + 291, + 178, + 'creature.png', + 18, + amountPerRow: 10, + textureWidth: textureWidth, + textureHeight: textureHeight, + stepTime: 0.15, + loop: true, + destroyOnFinish: true, + ); animationComponent.x = x - textureWidth / 2; animationComponent.y = y - textureHeight / 2; @@ -42,14 +54,15 @@ class MyGame extends BaseGame with TapDetector { MyGame(Size screenSize) { size = screenSize; - final animationComponent = AnimationComponent(100, 100, animation); - animationComponent.x = size.width / 2 - 100; - animationComponent.y = 100; + const s = 100.0; + final animationComponent = AnimationComponent(s, s, animation); + animationComponent.x = size.width / 2 - s; + animationComponent.y = s; final reversedAnimationComponent = - AnimationComponent(100, 100, animation.reversed()); + AnimationComponent(s, s, animation.reversed()); reversedAnimationComponent.x = size.width / 2; - reversedAnimationComponent.y = 100; + reversedAnimationComponent.y = s; add(animationComponent); add(reversedAnimationComponent); diff --git a/doc/examples/aseprite/lib/main.dart b/doc/examples/aseprite/lib/main.dart index df7d9434c..27e2350b2 100644 --- a/doc/examples/aseprite/lib/main.dart +++ b/doc/examples/aseprite/lib/main.dart @@ -18,7 +18,9 @@ class MyGame extends BaseGame { void _start() async { final animation = await flame_animation.Animation.fromAsepriteData( - 'chopper.png', 'chopper.json'); + 'chopper.png', + 'chopper.json', + ); final animationComponent = AnimationComponent(200, 200, animation); animationComponent.x = (size.width / 2) - 100; diff --git a/doc/examples/audiopool/lib/main.dart b/doc/examples/audiopool/lib/main.dart index f73d713a3..947664dfd 100644 --- a/doc/examples/audiopool/lib/main.dart +++ b/doc/examples/audiopool/lib/main.dart @@ -21,16 +21,17 @@ TextConfig regular = TextConfig(color: BasicPalette.white.color); AudioPool pool = AudioPool('laser.mp3'); class MyGame extends BaseGame with TapDetector { + static final black = BasicPalette.black.paint; + MyGame(Size screenSize) { size = screenSize; } @override void render(Canvas canvas) { - canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), - BasicPalette.black.paint); - regular.render(canvas, 'hit me!', Position.fromSize(size).div(2), - anchor: Anchor.center); + canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), black); + final p = Position.fromSize(size).div(2); + regular.render(canvas, 'hit me!', p, anchor: Anchor.center); super.render(canvas); } diff --git a/doc/examples/flare/lib/main.dart b/doc/examples/flare/lib/main.dart index af5dda162..f98c83f0a 100644 --- a/doc/examples/flare/lib/main.dart +++ b/doc/examples/flare/lib/main.dart @@ -19,7 +19,7 @@ class MyGame extends BaseGame with TapDetector { final TextConfig fpsTextConfig = TextConfig(color: const Color(0xFFFFFFFF)); final paint = Paint()..color = const Color(0xFFE5E5E5E5); - final List _animations = ["Stand", "Wave", "Jump", "Dance"]; + final List _animations = ['Stand', 'Wave', 'Jump', 'Dance']; int _currentAnimation = 0; FlareAnimation flareAnimation; @@ -48,26 +48,26 @@ class MyGame extends BaseGame with TapDetector { } void _start() async { - flareAnimation = await FlareAnimation.load("assets/Bob_Minion.flr"); - flareAnimation.updateAnimation("Stand"); + flareAnimation = await FlareAnimation.load('assets/Bob_Minion.flr'); + flareAnimation.updateAnimation('Stand'); flareAnimation.width = 306; flareAnimation.height = 228; final flareAnimation2 = - FlareComponent("assets/Bob_Minion.flr", "Wave", 306, 228); + FlareComponent('assets/Bob_Minion.flr', 'Wave', 306, 228); flareAnimation2.x = 50; flareAnimation2.y = 240; add(flareAnimation2); final flareAnimation3 = - FlareComponent("assets/Bob_Minion.flr", "Jump", 306, 228); + FlareComponent('assets/Bob_Minion.flr', 'Jump', 306, 228); flareAnimation3.x = 50; flareAnimation3.y = 400; add(flareAnimation3); final flareAnimation4 = - FlareComponent("assets/Bob_Minion.flr", "Dance", 306, 228); + FlareComponent('assets/Bob_Minion.flr', 'Dance', 306, 228); flareAnimation4.x = 50; flareAnimation4.y = 550; add(flareAnimation4); diff --git a/doc/examples/go_desktop/lib/game.dart b/doc/examples/go_desktop/lib/game.dart index 2ded7c8fd..8a099df21 100644 --- a/doc/examples/go_desktop/lib/game.dart +++ b/doc/examples/go_desktop/lib/game.dart @@ -3,7 +3,7 @@ import 'package:flame/game.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; -class MyGame extends BaseGame { +class MyGame extends Game { static final Paint paint = Paint()..color = const Color(0xFFFFFFFF); var movingLeft = false; @@ -24,19 +24,19 @@ class MyGame extends BaseGame { final keyLabel = e.data.logicalKey.keyLabel; - if (keyLabel == "a") { + if (keyLabel == 'a') { movingLeft = isKeyDown; } - if (keyLabel == "d") { + if (keyLabel == 'd') { movingRight = isKeyDown; } - if (keyLabel == "w") { + if (keyLabel == 'w') { movingUp = isKeyDown; } - if (keyLabel == "s") { + if (keyLabel == 's') { movingDown = isKeyDown; } }); diff --git a/doc/examples/keyboard/lib/main.dart b/doc/examples/keyboard/lib/main.dart index 917365f17..7486ac295 100644 --- a/doc/examples/keyboard/lib/main.dart +++ b/doc/examples/keyboard/lib/main.dart @@ -29,9 +29,9 @@ class MyGame extends Game with KeyboardEvents { @override void onKeyEvent(e) { final bool isKeyDown = e is RawKeyDownEvent; - if (e.data.keyLabel == "a") { + if (e.data.keyLabel == 'a') { _dir = isKeyDown ? -1 : 0; - } else if (e.data.keyLabel == "d") { + } else if (e.data.keyLabel == 'd') { _dir = isKeyDown ? 1 : 0; } } diff --git a/doc/examples/parallax/lib/main.dart b/doc/examples/parallax/lib/main.dart index 419be49fa..d71d0e5c8 100644 --- a/doc/examples/parallax/lib/main.dart +++ b/doc/examples/parallax/lib/main.dart @@ -12,15 +12,18 @@ void main() async { class MyGame extends BaseGame { MyGame() { final images = [ - ParallaxImage("bg.png"), - ParallaxImage("mountain-far.png"), - ParallaxImage("mountains.png"), - ParallaxImage("trees.png"), - ParallaxImage("foreground-trees.png"), + ParallaxImage('bg.png'), + ParallaxImage('mountain-far.png'), + ParallaxImage('mountains.png'), + ParallaxImage('trees.png'), + ParallaxImage('foreground-trees.png'), ]; - final parallaxComponent = ParallaxComponent(images, - baseSpeed: const Offset(20, 0), layerDelta: const Offset(30, 0)); + final parallaxComponent = ParallaxComponent( + images, + baseSpeed: const Offset(20, 0), + layerDelta: const Offset(30, 0), + ); add(parallaxComponent); } diff --git a/doc/examples/render_flip/lib/main.dart b/doc/examples/render_flip/lib/main.dart index be3ab507b..abf7fdfae 100644 --- a/doc/examples/render_flip/lib/main.dart +++ b/doc/examples/render_flip/lib/main.dart @@ -12,8 +12,13 @@ void main() async { } class MyGame extends BaseGame { - final animation = flame_animation.Animation.sequenced('chopper.png', 4, - textureWidth: 48, textureHeight: 48, stepTime: 0.15); + final animation = flame_animation.Animation.sequenced( + 'chopper.png', + 4, + textureWidth: 48, + textureHeight: 48, + stepTime: 0.15, + ); AnimationComponent buildAnimation() { final ac = AnimationComponent(100, 100, animation); diff --git a/doc/examples/sound/lib/main.dart b/doc/examples/sound/lib/main.dart index 06d729cfa..5cd05d64c 100644 --- a/doc/examples/sound/lib/main.dart +++ b/doc/examples/sound/lib/main.dart @@ -35,7 +35,6 @@ class Ball extends PositionComponent { } forward = !forward; - print('boin'); Flame.audio.play('boin.mp3', volume: 1.0); } } diff --git a/doc/examples/tiled/lib/main.dart b/doc/examples/tiled/lib/main.dart index 0cab05292..be2540b9f 100644 --- a/doc/examples/tiled/lib/main.dart +++ b/doc/examples/tiled/lib/main.dart @@ -22,7 +22,7 @@ class TiledGame extends BaseGame { void _addCoinsInMap(TiledComponent tiledMap) async { final ObjectGroup objGroup = - await tiledMap.getObjectGroupFromLayer("AnimatedCoins"); + await tiledMap.getObjectGroupFromLayer('AnimatedCoins'); if (objGroup == null) { return; } diff --git a/doc/examples/tiled/pubspec.yaml b/doc/examples/tiled/pubspec.yaml index 5592ddffa..72acf8a96 100644 --- a/doc/examples/tiled/pubspec.yaml +++ b/doc/examples/tiled/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: sdk: flutter flame: path: ../../../ + tiled: 0.6.0 dev_dependencies: flutter_test: diff --git a/lib/components/animation_component.dart b/lib/components/animation_component.dart index 7472ff035..c33662dbf 100644 --- a/lib/components/animation_component.dart +++ b/lib/components/animation_component.dart @@ -1,15 +1,19 @@ import 'dart:ui'; import 'component.dart'; -import 'package:flame/animation.dart'; +import '../animation.dart'; class AnimationComponent extends PositionComponent { Animation animation; Paint overridePaint; bool destroyOnFinish = false; - AnimationComponent(double width, double height, this.animation, - {this.destroyOnFinish = false}) { + AnimationComponent( + double width, + double height, + this.animation, { + this.destroyOnFinish = false, + }) { this.width = width; this.height = height; } @@ -54,8 +58,12 @@ class AnimationComponent extends PositionComponent { @override void render(Canvas canvas) { prepareCanvas(canvas); - animation.getSprite().render(canvas, - width: width, height: height, overridePaint: overridePaint); + animation.getSprite().render( + canvas, + width: width, + height: height, + overridePaint: overridePaint, + ); } @override From 366da7bb9d4ad2f8bff191e6e1d8cda916ad6e49 Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Sun, 2 Aug 2020 16:24:06 -0400 Subject: [PATCH 2/2] More fixes --- doc/examples/animations/lib/main.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/examples/animations/lib/main.dart b/doc/examples/animations/lib/main.dart index 81500b7d8..26d953ebf 100644 --- a/doc/examples/animations/lib/main.dart +++ b/doc/examples/animations/lib/main.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - await Flame.images.loadAll(['creture.png', 'chopper.png']); + await Flame.images.loadAll(['creature.png', 'chopper.png']); final Size size = await Flame.util.initialDimensions(); final game = MyGame(size); @@ -37,7 +37,7 @@ class MyGame extends BaseGame with TapDetector { textureWidth: textureWidth, textureHeight: textureHeight, stepTime: 0.15, - loop: true, + loop: false, destroyOnFinish: true, ); animationComponent.x = x - textureWidth / 2;