mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
57 lines
1.3 KiB
Dart
57 lines
1.3 KiB
Dart
import 'package:flame/sprite_animation.dart';
|
|
import 'package:flame/components/sprite_animation_component.dart';
|
|
import 'package:flame/flame.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame/extensions/vector2.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final Vector2 size = await Flame.util.initialDimensions();
|
|
final game = MyGame(size);
|
|
runApp(
|
|
GameWidget(
|
|
game: game,
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyGame extends BaseGame {
|
|
SpriteAnimation animation;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final image = await images.load('chopper.png');
|
|
animation = SpriteAnimation.sequenced(
|
|
image,
|
|
4,
|
|
textureSize: Vector2.all(48),
|
|
stepTime: 0.15,
|
|
);
|
|
|
|
final regular = buildAnimation();
|
|
regular.y = 100;
|
|
add(regular);
|
|
|
|
final flipX = buildAnimation();
|
|
flipX.y = 300;
|
|
flipX.renderFlipX = true;
|
|
add(flipX);
|
|
|
|
final flipY = buildAnimation();
|
|
flipY.y = 500;
|
|
flipY.renderFlipY = true;
|
|
add(flipY);
|
|
}
|
|
|
|
SpriteAnimationComponent buildAnimation() {
|
|
final ac = SpriteAnimationComponent(Vector2.all(100), animation);
|
|
ac.x = size.x / 2 - ac.x / 2;
|
|
return ac;
|
|
}
|
|
|
|
MyGame(Vector2 screenSize) {
|
|
size = screenSize;
|
|
}
|
|
}
|