mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-01 10:38:17 +08:00
* 👌 Use `Offset` type directly in `JoystickAction.update` calculations (#631) * Move files to src and comply with the dart package layout convention * Fixing widgets example Co-authored-by: Serge Matveenko <lig@countzero.co> Co-authored-by: Erick Zanardo <erickzanardoo@gmail.com>
56 lines
1.2 KiB
Dart
56 lines
1.2 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flutter/material.dart' hide Image;
|
|
import 'dart:ui';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final game = MyGame();
|
|
runApp(
|
|
GameWidget(
|
|
game: game,
|
|
),
|
|
);
|
|
}
|
|
|
|
class MyGame extends BaseGame {
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final image = await images.load('chopper.png');
|
|
|
|
final regular = buildAnimationComponent(image);
|
|
regular.y = 100;
|
|
add(regular);
|
|
|
|
final flipX = buildAnimationComponent(image);
|
|
flipX.y = 300;
|
|
flipX.renderFlipX = true;
|
|
add(flipX);
|
|
|
|
final flipY = buildAnimationComponent(image);
|
|
flipY.y = 500;
|
|
flipY.renderFlipY = true;
|
|
add(flipY);
|
|
}
|
|
|
|
SpriteAnimationComponent buildAnimationComponent(Image image) {
|
|
final ac = SpriteAnimationComponent.fromSpriteAnimation(
|
|
Vector2.all(100),
|
|
buildAnimation(image),
|
|
);
|
|
ac.x = size.x / 2 - ac.x / 2;
|
|
return ac;
|
|
}
|
|
|
|
SpriteAnimation buildAnimation(Image image) {
|
|
return SpriteAnimation.fromFrameData(
|
|
image,
|
|
SpriteAnimationData.sequenced(
|
|
amount: 4,
|
|
textureSize: Vector2.all(48),
|
|
stepTime: 0.15,
|
|
),
|
|
);
|
|
}
|
|
}
|