Removing prefix from FlameSpriteWidget and FlameAnimationWidget

This commit is contained in:
Erick Zanardo
2020-05-30 12:44:10 -03:00
parent 26ab1d2217
commit 19b57b0c38
8 changed files with 29 additions and 29 deletions

View File

@ -2,8 +2,8 @@
## [next] ## [next]
- Fixing BaseGame tap detectors issues - Fixing BaseGame tap detectors issues
- Adding FlameSpriteWidget - Adding SpriteWidget
- Adding FlameAnimationWidget - Adding AnimationWidget
- Upgrade Flutter SVG to fix for flame web - Upgrade Flutter SVG to fix for flame web
- Add linting to all the examples - Add linting to all the examples

View File

@ -4,7 +4,7 @@
As for Flame 0.22.0 there is a new way to use Animations and Sprites inside your widget tree. As for Flame 0.22.0 there is a new way to use Animations and Sprites inside your widget tree.
Flame now includes a widget catalog and inside it you will find `FlameAnimationWidget` and `FlameSpriteWidget`. Flame now includes a widget catalog and inside it you will find `AnimationWidget` and `SpriteWidget`.
Check the example mentioned on this article to see the updated version. Check the example mentioned on this article to see the updated version.

View File

@ -5,8 +5,8 @@ import 'package:flame/animation.dart' as animation;
import 'package:flame/sprite.dart'; import 'package:flame/sprite.dart';
import 'package:flame/spritesheet.dart'; import 'package:flame/spritesheet.dart';
import 'package:flame/position.dart'; import 'package:flame/position.dart';
import 'package:flame/widgets/flame_animation_widget.dart'; import 'package:flame/widgets/animation_widget.dart';
import 'package:flame/widgets/flame_sprite_widget.dart'; import 'package:flame/widgets/sprite_widget.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
Sprite _sprite; Sprite _sprite;
@ -91,7 +91,7 @@ class _MyHomePageState extends State<MyHomePage> {
Container( Container(
width: 200, width: 200,
height: 200, height: 200,
child: FlameAnimationWidget(animation: _animation), child: AnimationWidget(animation: _animation),
), ),
const Text('Neat, hum?'), const Text('Neat, hum?'),
const Text( const Text(
@ -99,7 +99,7 @@ class _MyHomePageState extends State<MyHomePage> {
Container( Container(
width: 200, width: 200,
height: 200, height: 200,
child: FlameSpriteWidget(sprite: _sprite), child: SpriteWidget(sprite: _sprite),
), ),
const Text('Sprites from Elthen\'s amazing work on itch.io:'), const Text('Sprites from Elthen\'s amazing work on itch.io:'),
const Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'), const Text('https://elthen.itch.io/2d-pixel-art-minotaur-sprites'),

View File

@ -6,8 +6,8 @@ import 'package:dashbook/dashbook.dart';
import 'package:flame/widgets/nine_tile_box.dart'; import 'package:flame/widgets/nine_tile_box.dart';
import 'package:flame/widgets/sprite_button.dart'; import 'package:flame/widgets/sprite_button.dart';
import 'package:flame/widgets/flame_sprite_widget.dart'; import 'package:flame/widgets/sprite_widget.dart';
import 'package:flame/widgets/flame_animation_widget.dart'; import 'package:flame/widgets/animation_widget.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -64,13 +64,13 @@ void main() async {
); );
final shieldSprite = await Sprite.loadSprite('shield.png'); final shieldSprite = await Sprite.loadSprite('shield.png');
dashbook.storiesOf('FlameSpriteWidget').decorator(CenterDecorator()).add( dashbook.storiesOf('SpriteWidget').decorator(CenterDecorator()).add(
'default', 'default',
(ctx) => Container( (ctx) => Container(
width: ctx.numberProperty('container width', 400), width: ctx.numberProperty('container width', 400),
height: ctx.numberProperty('container height', 200), height: ctx.numberProperty('container height', 200),
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
child: FlameSpriteWidget( child: SpriteWidget(
sprite: shieldSprite, sprite: shieldSprite,
center: ctx.boolProperty('center', true), center: ctx.boolProperty('center', true),
), ),
@ -91,13 +91,13 @@ void main() async {
to: 3, to: 3,
loop: true, loop: true,
); );
dashbook.storiesOf('FlameAnimationWidget').decorator(CenterDecorator()).add( dashbook.storiesOf('AnimationWidget').decorator(CenterDecorator()).add(
'default', 'default',
(ctx) => Container( (ctx) => Container(
width: ctx.numberProperty('container width', 400), width: ctx.numberProperty('container width', 400),
height: ctx.numberProperty('container height', 200), height: ctx.numberProperty('container height', 200),
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
child: FlameAnimationWidget( child: AnimationWidget(
animation: _animation, animation: _animation,
play: ctx.boolProperty('playing', true), play: ctx.boolProperty('playing', true),
center: ctx.boolProperty('center', true), center: ctx.boolProperty('center', true),

View File

@ -48,28 +48,28 @@ SpriteButton(
) )
``` ```
## FlameSpriteWidget ## SpriteWidget
`FlameSpriteWidget` is a widget used to display [Sprites](https://github.com/flame-engine/flame/blob/master/lib/sprite.dart) inside a widget tree. `SpriteWidget` is a widget used to display [Sprites](https://github.com/flame-engine/flame/blob/master/lib/sprite.dart) inside a widget tree.
How to use it: How to use it:
```dart ```dart
FlameSpriteWidget( SpriteWidget(
sprite: shieldSprite, sprite: shieldSprite,
center: true, center: true,
), ),
``` ```
## FlameAnimationWidget ## AnimationWidget
`FlameAnimationWidget` is a widget used to display [Animations](https://github.com/flame-engine/flame/blob/master/lib/animation.dart) inside a widget tree. `AnimationWidget` is a widget used to display [Animations](https://github.com/flame-engine/flame/blob/master/lib/animation.dart) inside a widget tree.
How to use it: How to use it:
```dart ```dart
FlameAnimationWidget( AnimationWidget(
animation: _animation, animation: _animation,
play: true, play: true,
center: true, center: true,

View File

@ -155,7 +155,7 @@ class Util {
/// You can use this implementation as base to easily create your own widgets based on more complex games. /// You can use this implementation as base to easily create your own widgets based on more complex games.
/// 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.
/// ///
@Deprecated('Use FlameSpriteAnimation instead') @Deprecated('Use SpriteAnimation instead')
widgets.Widget animationAsWidget(Position size, Animation animation) { widgets.Widget animationAsWidget(Position size, Animation animation) {
return EmbeddedGameWidget( return EmbeddedGameWidget(
BaseGame()..add(AnimationComponent(size.x, size.y, animation)), BaseGame()..add(AnimationComponent(size.x, size.y, animation)),
@ -168,7 +168,7 @@ class Util {
/// This will create a [CustomPaint] widget using a [CustomPainter] for rendering the [Sprite] /// This will create a [CustomPaint] widget using a [CustomPainter] for rendering the [Sprite]
/// Be aware that the Sprite must have been loaded, otherwise it can't be rendered /// Be aware that the Sprite must have been loaded, otherwise it can't be rendered
/// ///
@Deprecated('Use FlameSpriteWidget instead') @Deprecated('Use SpriteWidget instead')
widgets.CustomPaint spriteAsWidget(Size size, Sprite sprite) => widgets.CustomPaint spriteAsWidget(Size size, Sprite sprite) =>
widgets.CustomPaint(size: size, painter: _SpriteCustomPainter(sprite)); widgets.CustomPaint(size: size, painter: _SpriteCustomPainter(sprite));
} }

View File

@ -1,26 +1,26 @@
import 'package:flutter/material.dart' hide Animation; import 'package:flutter/material.dart' hide Animation;
import 'package:flame/animation.dart'; import 'package:flame/animation.dart';
import './flame_sprite_widget.dart'; import './sprite_widget.dart';
import 'dart:math'; import 'dart:math';
class FlameAnimationWidget extends StatefulWidget { class AnimationWidget extends StatefulWidget {
final Animation animation; final Animation animation;
final bool center; final bool center;
final bool play; final bool play;
FlameAnimationWidget({ AnimationWidget({
this.animation, this.animation,
this.play = true, this.play = true,
this.center = false, this.center = false,
}) : assert(animation.loaded(), 'Animation must be loaded'); }) : assert(animation.loaded(), 'Animation must be loaded');
@override @override
State createState() => _FlameAnimationWidget(); State createState() => _AnimationWidget();
} }
class _FlameAnimationWidget extends State<FlameAnimationWidget> class _AnimationWidget extends State<AnimationWidget>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
AnimationController _controller; AnimationController _controller;
double _lastUpdated; double _lastUpdated;
@ -82,7 +82,7 @@ class _FlameAnimationWidget extends State<FlameAnimationWidget>
@override @override
Widget build(ctx) { Widget build(ctx) {
return FlameSpriteWidget( return SpriteWidget(
sprite: widget.animation.getSprite(), center: widget.center); sprite: widget.animation.getSprite(), center: widget.center);
} }
} }

View File

@ -4,11 +4,11 @@ import '../sprite.dart';
import 'dart:math'; import 'dart:math';
class FlameSpriteWidget extends StatelessWidget { class SpriteWidget extends StatelessWidget {
final Sprite sprite; final Sprite sprite;
final bool center; final bool center;
FlameSpriteWidget({ SpriteWidget({
@required this.sprite, @required this.sprite,
this.center = false, this.center = false,
}) : assert(sprite.loaded(), 'Sprite must be loaded'); }) : assert(sprite.loaded(), 'Sprite must be loaded');