mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 03:15:43 +08:00
Fixing more examples
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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<void> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,15 +18,10 @@ class MyGame extends BaseGame {
|
||||
}
|
||||
|
||||
@override
|
||||
void onAttach() {
|
||||
super.onAttach();
|
||||
|
||||
initSprites();
|
||||
}
|
||||
|
||||
void initSprites() async {
|
||||
Future<void> 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();
|
||||
|
||||
@ -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<void> 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
|
||||
|
||||
@ -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<void> 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);
|
||||
|
||||
@ -9,7 +9,6 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
dashbook: 0.0.6
|
||||
flame:
|
||||
path: ../../../
|
||||
|
||||
|
||||
Reference in New Issue
Block a user