// lib/main.dart
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flame/components.dart';
import 'package:flutter/widgets.dart';
class RunnerGame extends FlameGame with TapDetector {
late SpriteAnimationComponent hero;
@override
Future<void> onLoad() async {
final image = await images.load('hero_run.png'); // spritesheet
final animation = SpriteAnimation.fromFrameData(
image,
SpriteAnimationData.sequenced(
amount: 8, stepTime: 0.08, textureSize: Vector2(64, 64),
),
);
hero = SpriteAnimationComponent(animation: animation, size: Vector2(128, 128))
..position = size / 2;
add(hero);
}
@override
void onTapDown(TapDownInfo info) {
hero.add(MoveToEffect(info.eventPosition.game, EffectController(duration: 0.3)));
}
}
void main() {
final game = RunnerGame();
runApp(GameWidget(game: game));
}