mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
Fixing more examples
This commit is contained in:
@ -19,7 +19,7 @@ void main() async {
|
|||||||
|
|
||||||
await Flame.images.load('minotaur.png');
|
await Flame.images.load('minotaur.png');
|
||||||
final _animationSpriteSheet = SpriteSheet(
|
final _animationSpriteSheet = SpriteSheet(
|
||||||
imageName: 'minotaur.png',
|
image: image,
|
||||||
columns: 19,
|
columns: 19,
|
||||||
rows: 1,
|
rows: 1,
|
||||||
textureWidth: 96,
|
textureWidth: 96,
|
||||||
|
|||||||
@ -12,22 +12,18 @@ void main() async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyGame extends BaseGame {
|
class MyGame extends BaseGame {
|
||||||
final animation = SpriteAnimation.sequenced(
|
SpriteAnimation animation;
|
||||||
'chopper.png',
|
|
||||||
4,
|
|
||||||
textureWidth: 48,
|
|
||||||
textureHeight: 48,
|
|
||||||
stepTime: 0.15,
|
|
||||||
);
|
|
||||||
|
|
||||||
SpriteAnimationComponent buildAnimation() {
|
@override
|
||||||
final ac = SpriteAnimationComponent(100, 100, animation);
|
Future<void> onLoad() async {
|
||||||
ac.x = size.width / 2 - ac.width / 2;
|
final image = await images.load('chopper.png');
|
||||||
return ac;
|
animation = SpriteAnimation.sequenced(
|
||||||
}
|
image,
|
||||||
|
4,
|
||||||
MyGame(Size screenSize) {
|
textureWidth: 48,
|
||||||
size = screenSize;
|
textureHeight: 48,
|
||||||
|
stepTime: 0.15,
|
||||||
|
);
|
||||||
|
|
||||||
final regular = buildAnimation();
|
final regular = buildAnimation();
|
||||||
regular.y = 100;
|
regular.y = 100;
|
||||||
@ -43,4 +39,14 @@ class MyGame extends BaseGame {
|
|||||||
flipY.renderFlipY = true;
|
flipY.renderFlipY = true;
|
||||||
add(flipY);
|
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
|
@override
|
||||||
void onAttach() {
|
Future<void> onLoad() async {
|
||||||
super.onAttach();
|
|
||||||
|
|
||||||
initSprites();
|
|
||||||
}
|
|
||||||
|
|
||||||
void initSprites() async {
|
|
||||||
final r = Random();
|
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) {
|
.forEach((sprite) {
|
||||||
sprite.x = r.nextInt(size.width.toInt()).toDouble();
|
sprite.x = r.nextInt(size.width.toInt()).toDouble();
|
||||||
sprite.y = r.nextInt(size.height.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/sprite.dart';
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
|
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
void main() async {
|
void main() {
|
||||||
const exampleUrl =
|
runApp(MyGame().widget);
|
||||||
'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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyGame extends Game {
|
class MyGame extends Game {
|
||||||
Sprite _sprite;
|
Sprite _sprite;
|
||||||
|
|
||||||
MyGame(Image image) {
|
@override
|
||||||
_sprite = Sprite.fromImage(image);
|
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
|
@override
|
||||||
|
|||||||
@ -1,57 +1,26 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flame/components/sprite_animation_component.dart';
|
import 'package:flame/components/sprite_animation_component.dart';
|
||||||
import 'package:flame/components/sprite_component.dart';
|
import 'package:flame/components/sprite_component.dart';
|
||||||
import 'package:flame/flame.dart';
|
|
||||||
import 'package:flame/game.dart';
|
import 'package:flame/game.dart';
|
||||||
import 'package:flame/spritesheet.dart';
|
import 'package:flame/spritesheet.dart';
|
||||||
import 'package:dashbook/dashbook.dart';
|
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
final spriteSheet = SpriteSheet(
|
runApp(MyGame().widget);
|
||||||
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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyGame extends BaseGame {
|
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 =
|
final vampireAnimation =
|
||||||
spriteSheet.createAnimation(0, stepTime: 0.1, to: 7);
|
spriteSheet.createAnimation(0, stepTime: 0.1, to: 7);
|
||||||
final ghostAnimation = spriteSheet.createAnimation(1, stepTime: 0.1, to: 7);
|
final ghostAnimation = spriteSheet.createAnimation(1, stepTime: 0.1, to: 7);
|
||||||
|
|||||||
@ -9,7 +9,6 @@ environment:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flutter:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
dashbook: 0.0.6
|
|
||||||
flame:
|
flame:
|
||||||
path: ../../../
|
path: ../../../
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user