diff --git a/doc/examples/animation_widget/lib/main.dart b/doc/examples/animation_widget/lib/main.dart index 809bbb4ab..ac54e663e 100644 --- a/doc/examples/animation_widget/lib/main.dart +++ b/doc/examples/animation_widget/lib/main.dart @@ -19,7 +19,7 @@ void main() async { await Flame.images.load('minotaur.png'); final _animationSpriteSheet = SpriteSheet( - imageName: 'minotaur.png', + image: image, columns: 19, rows: 1, textureWidth: 96, diff --git a/doc/examples/render_flip/lib/main.dart b/doc/examples/render_flip/lib/main.dart index 1943b91ee..2ffe660d8 100644 --- a/doc/examples/render_flip/lib/main.dart +++ b/doc/examples/render_flip/lib/main.dart @@ -12,22 +12,18 @@ void main() async { } class MyGame extends BaseGame { - final animation = SpriteAnimation.sequenced( - 'chopper.png', - 4, - textureWidth: 48, - textureHeight: 48, - stepTime: 0.15, - ); + SpriteAnimation animation; - SpriteAnimationComponent buildAnimation() { - final ac = SpriteAnimationComponent(100, 100, animation); - ac.x = size.width / 2 - ac.width / 2; - return ac; - } - - MyGame(Size screenSize) { - size = screenSize; + @override + Future onLoad() async { + final image = await images.load('chopper.png'); + animation = SpriteAnimation.sequenced( + image, + 4, + textureWidth: 48, + textureHeight: 48, + stepTime: 0.15, + ); final regular = buildAnimation(); regular.y = 100; @@ -43,4 +39,14 @@ class MyGame extends BaseGame { flipY.renderFlipY = true; add(flipY); } + + SpriteAnimationComponent buildAnimation() { + final ac = SpriteAnimationComponent(100, 100, animation); + ac.x = size.width / 2 - ac.width / 2; + return ac; + } + + MyGame(Size screenSize) { + size = screenSize; + } } diff --git a/doc/examples/sprites/lib/main.dart b/doc/examples/sprites/lib/main.dart index aa6ced156..258f11195 100644 --- a/doc/examples/sprites/lib/main.dart +++ b/doc/examples/sprites/lib/main.dart @@ -18,15 +18,10 @@ class MyGame extends BaseGame { } @override - void onAttach() { - super.onAttach(); - - initSprites(); - } - - void initSprites() async { + Future onLoad() async { final r = Random(); - List.generate(500, (i) => SpriteComponent.square(32, 'test.png')) + final image = await images.load('test.png'); + List.generate(500, (i) => SpriteComponent.square(32, image)) .forEach((sprite) { sprite.x = r.nextInt(size.width.toInt()).toDouble(); sprite.y = r.nextInt(size.height.toInt()).toDouble(); diff --git a/doc/examples/sprites/lib/main_base64.dart b/doc/examples/sprites/lib/main_base64.dart index b77938acd..dbeb4b08c 100644 --- a/doc/examples/sprites/lib/main_base64.dart +++ b/doc/examples/sprites/lib/main_base64.dart @@ -1,25 +1,23 @@ -import 'package:flutter/material.dart' hide Image; +import 'package:flutter/material.dart'; -import 'package:flame/flame.dart'; import 'package:flame/sprite.dart'; import 'package:flame/game.dart'; import 'dart:ui'; -void main() async { - const exampleUrl = - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAxElEQVQ4jYWTMQ7DIAxFIeoNuAGK1K1ISL0DMwOHzNC5p6iUPeoNOEM7GZnPJ/EUbP7Lx7KtIfH91B/L++gs5m5M9NreTN/dEZiVghatwbXvY68UlksyPjprRaxFGAJZg+uAuSSzzC7rEDirDYAz2wg0RjWRFa/EUwdnQnQ37QFe1Odjrw04AKTTaBXPAlx8dDaXdNk4rMsc0B7ge/UcYLTZxoFizxCQ/L0DMAhaX4Mzj/uzW6phu3AvtHUUU4BAWJ6t8x9N/HHcruXjwQAAAABJRU5ErkJggg=='; - - final image = await Flame.images.fromBase64('shield.png', exampleUrl); - - runApp(MyGame(image).widget); +void main() { + runApp(MyGame().widget); } class MyGame extends Game { Sprite _sprite; - MyGame(Image image) { - _sprite = Sprite.fromImage(image); + @override + Future onLoad() async { + const exampleUrl = + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAxElEQVQ4jYWTMQ7DIAxFIeoNuAGK1K1ISL0DMwOHzNC5p6iUPeoNOEM7GZnPJ/EUbP7Lx7KtIfH91B/L++gs5m5M9NreTN/dEZiVghatwbXvY68UlksyPjprRaxFGAJZg+uAuSSzzC7rEDirDYAz2wg0RjWRFa/EUwdnQnQ37QFe1Odjrw04AKTTaBXPAlx8dDaXdNk4rMsc0B7ge/UcYLTZxoFizxCQ/L0DMAhaX4Mzj/uzW6phu3AvtHUUU4BAWJ6t8x9N/HHcruXjwQAAAABJRU5ErkJggg=='; + final image = await images.fromBase64('shield.png', exampleUrl); + _sprite = Sprite(image); } @override diff --git a/doc/examples/spritesheet/lib/main.dart b/doc/examples/spritesheet/lib/main.dart index 743d62a50..c61113fc8 100644 --- a/doc/examples/spritesheet/lib/main.dart +++ b/doc/examples/spritesheet/lib/main.dart @@ -1,57 +1,26 @@ import 'package:flutter/material.dart'; import 'package:flame/components/sprite_animation_component.dart'; import 'package:flame/components/sprite_component.dart'; -import 'package:flame/flame.dart'; import 'package:flame/game.dart'; import 'package:flame/spritesheet.dart'; -import 'package:dashbook/dashbook.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - final spriteSheet = SpriteSheet( - imageName: 'spritesheet.png', - textureWidth: 16, - textureHeight: 18, - columns: 11, - rows: 2, - ); - - final spriteSheetFromImage = SpriteSheet.fromImage( - image: await Flame.images.load('spritesheet.png'), - textureWidth: 16, - textureHeight: 18, - columns: 11, - rows: 2, - ); - - final dashbook = Dashbook(); - - dashbook - .storiesOf('SpriteSheet') - .add('defaut', (_) => GameWrapper(MyGame(spriteSheet))) - .add('fromImage', (_) => GameWrapper(MyGame(spriteSheetFromImage))); - - runApp(dashbook); -} - -class GameWrapper extends StatelessWidget { - final Game game; - - GameWrapper(this.game); - - @override - Widget build(_) { - return Container( - width: 400, - height: 400, - child: game.widget, - ); - } + runApp(MyGame().widget); } class MyGame extends BaseGame { - MyGame(SpriteSheet spriteSheet) { + @override + Future onLoad() async { + final spriteSheet = SpriteSheet( + image: await images.load('spritesheet.png'), + textureWidth: 16, + textureHeight: 18, + columns: 11, + rows: 2, + ); + final vampireAnimation = spriteSheet.createAnimation(0, stepTime: 0.1, to: 7); final ghostAnimation = spriteSheet.createAnimation(1, stepTime: 0.1, to: 7); diff --git a/doc/examples/spritesheet/pubspec.yaml b/doc/examples/spritesheet/pubspec.yaml index dec48fabf..77ea24983 100644 --- a/doc/examples/spritesheet/pubspec.yaml +++ b/doc/examples/spritesheet/pubspec.yaml @@ -9,7 +9,6 @@ environment: dependencies: flutter: sdk: flutter - dashbook: 0.0.6 flame: path: ../../../