diff --git a/doc/examples/animation_widget/.gitignore b/doc/examples/animation_widget/.gitignore index 47e0b4d62..37f79a857 100644 --- a/doc/examples/animation_widget/.gitignore +++ b/doc/examples/animation_widget/.gitignore @@ -69,3 +69,7 @@ build/ !**/ios/**/default.pbxuser !**/ios/**/default.perspectivev3 !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages + +macos +test +.flutter-plugins-dependencies diff --git a/doc/examples/animation_widget/lib/main.dart b/doc/examples/animation_widget/lib/main.dart index 17dfb11f4..def77deb0 100644 --- a/doc/examples/animation_widget/lib/main.dart +++ b/doc/examples/animation_widget/lib/main.dart @@ -9,6 +9,7 @@ import 'package:flutter/material.dart'; Sprite _sprite; void main() async { + WidgetsFlutterBinding.ensureInitialized(); _sprite = await Sprite.loadSprite('minotaur.png', width: 96, height: 96); runApp(MyApp()); } @@ -71,7 +72,7 @@ class _MyHomePageState extends State { Flame.util.animationAsWidget( _position, animation.Animation.sequenced('minotaur.png', 19, - textureWidth: 96.0)), + textureWidth: 96.0, textureHeight: 96)), const Text('Neat, hum?'), const Text( 'By the way, you can also use static sprites as widgets:'), diff --git a/lib/game/base_game.dart b/lib/game/base_game.dart index c5038fe0b..d0334a37b 100644 --- a/lib/game/base_game.dart +++ b/lib/game/base_game.dart @@ -21,7 +21,7 @@ import 'game.dart'; /// It still needs to be subclasses to add your game logic, but the [update], [render] and [resize] methods have default implementations. /// This is the recommended structure to use for most games. /// It is based on the Component system. -abstract class BaseGame extends Game with TapDetector { +class BaseGame extends Game with TapDetector { /// The list of components to be updated and rendered by the base game. OrderedSet components = OrderedSet(Comparing.on((c) => c.priority())); diff --git a/lib/game/embedded_game_widget.dart b/lib/game/embedded_game_widget.dart index 634612e96..620e69db7 100644 --- a/lib/game/embedded_game_widget.dart +++ b/lib/game/embedded_game_widget.dart @@ -6,7 +6,7 @@ import '../position.dart'; import 'game_render_box.dart'; import 'game.dart'; -/// This a widget to embed a game inside the Widget tree. You can use it in pair with [SimpleGame] or any other more complex [Game], as desired. +/// This a widget to embed a game inside the Widget tree. You can use it in pair with [BaseGame] or any other more complex [Game], as desired. /// /// It handles for you positioning, size constraints and other factors that arise when your game is embedded within the component tree. /// Provided it with a [Game] instance for your game and the optional size of the widget. diff --git a/lib/game/simple_game.dart b/lib/game/simple_game.dart deleted file mode 100644 index e020122b4..000000000 --- a/lib/game/simple_game.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flame/components/component.dart'; - -import 'base_game.dart'; - -/// This is a helper implementation of a [BaseGame] designed to allow to easily create a game with a single component. -/// -/// This is useful to add sprites, animations and other Flame components "directly" to your non-game Flutter widget tree, when combined with [EmbeddedGameWidget]. -class SimpleGame extends BaseGame { - SimpleGame(Component c) { - add(c); - } -} diff --git a/lib/util.dart b/lib/util.dart index 1c03ab6af..bf665eb09 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -6,8 +6,8 @@ import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart' as widgets; import 'animation.dart'; +import 'game/base_game.dart'; import 'game/embedded_game_widget.dart'; -import 'game/simple_game.dart'; import 'sprite.dart'; import 'components/animation_component.dart'; import 'position.dart'; @@ -155,7 +155,7 @@ class Util { /// This is intended to be used by non-game apps that want to add a sprite sheet animation. widgets.Widget animationAsWidget(Position size, Animation animation) { return EmbeddedGameWidget( - SimpleGame(AnimationComponent(size.x, size.y, animation)), + BaseGame()..add(AnimationComponent(size.x, size.y, animation)), size: size); }