mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 08:56:01 +08:00 
			
		
		
		
	make BaseGame non-abstract and remove SimpleGame | fix animation example
This commit is contained in:
		
							
								
								
									
										4
									
								
								doc/examples/animation_widget/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								doc/examples/animation_widget/.gitignore
									
									
									
									
										vendored
									
									
								
							| @ -69,3 +69,7 @@ build/ | |||||||
| !**/ios/**/default.pbxuser | !**/ios/**/default.pbxuser | ||||||
| !**/ios/**/default.perspectivev3 | !**/ios/**/default.perspectivev3 | ||||||
| !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages | ||||||
|  |  | ||||||
|  | macos | ||||||
|  | test | ||||||
|  | .flutter-plugins-dependencies | ||||||
|  | |||||||
| @ -9,6 +9,7 @@ import 'package:flutter/material.dart'; | |||||||
| Sprite _sprite; | Sprite _sprite; | ||||||
|  |  | ||||||
| void main() async { | void main() async { | ||||||
|  |   WidgetsFlutterBinding.ensureInitialized(); | ||||||
|   _sprite = await Sprite.loadSprite('minotaur.png', width: 96, height: 96); |   _sprite = await Sprite.loadSprite('minotaur.png', width: 96, height: 96); | ||||||
|   runApp(MyApp()); |   runApp(MyApp()); | ||||||
| } | } | ||||||
| @ -71,7 +72,7 @@ class _MyHomePageState extends State<MyHomePage> { | |||||||
|             Flame.util.animationAsWidget( |             Flame.util.animationAsWidget( | ||||||
|                 _position, |                 _position, | ||||||
|                 animation.Animation.sequenced('minotaur.png', 19, |                 animation.Animation.sequenced('minotaur.png', 19, | ||||||
|                     textureWidth: 96.0)), |                     textureWidth: 96.0, textureHeight: 96)), | ||||||
|             const Text('Neat, hum?'), |             const Text('Neat, hum?'), | ||||||
|             const Text( |             const Text( | ||||||
|                 'By the way, you can also use static sprites as widgets:'), |                 'By the way, you can also use static sprites as widgets:'), | ||||||
|  | |||||||
| @ -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. | /// 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. | /// This is the recommended structure to use for most games. | ||||||
| /// It is based on the Component system. | /// 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. |   /// The list of components to be updated and rendered by the base game. | ||||||
|   OrderedSet<Component> components = |   OrderedSet<Component> components = | ||||||
|       OrderedSet(Comparing.on((c) => c.priority())); |       OrderedSet(Comparing.on((c) => c.priority())); | ||||||
|  | |||||||
| @ -6,7 +6,7 @@ import '../position.dart'; | |||||||
| import 'game_render_box.dart'; | import 'game_render_box.dart'; | ||||||
| import 'game.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. | /// 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. | /// Provided it with a [Game] instance for your game and the optional size of the widget. | ||||||
|  | |||||||
| @ -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); |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @ -6,8 +6,8 @@ import 'package:flutter/services.dart'; | |||||||
| import 'package:flutter/widgets.dart' as widgets; | import 'package:flutter/widgets.dart' as widgets; | ||||||
|  |  | ||||||
| import 'animation.dart'; | import 'animation.dart'; | ||||||
|  | import 'game/base_game.dart'; | ||||||
| import 'game/embedded_game_widget.dart'; | import 'game/embedded_game_widget.dart'; | ||||||
| import 'game/simple_game.dart'; |  | ||||||
| import 'sprite.dart'; | import 'sprite.dart'; | ||||||
| import 'components/animation_component.dart'; | import 'components/animation_component.dart'; | ||||||
| import 'position.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. |   /// 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) { |   widgets.Widget animationAsWidget(Position size, Animation animation) { | ||||||
|     return EmbeddedGameWidget( |     return EmbeddedGameWidget( | ||||||
|         SimpleGame(AnimationComponent(size.x, size.y, animation)), |         BaseGame()..add(AnimationComponent(size.x, size.y, animation)), | ||||||
|         size: size); |         size: size); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Erlend Fagerheim
					Erlend Fagerheim