make BaseGame non-abstract and remove SimpleGame | fix animation example

This commit is contained in:
Erlend Fagerheim
2020-04-21 16:34:39 +02:00
parent 48a21cc74c
commit 4386f47fc4
6 changed files with 10 additions and 17 deletions

View File

@ -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

View File

@ -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<MyHomePage> {
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:'),

View File

@ -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<Component> components =
OrderedSet(Comparing.on((c) => c.priority()));

View File

@ -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.

View File

@ -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);
}
}

View File

@ -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);
}