mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-12 02:19:49 +08:00
This PR adds a new package which makes it easier to parse and render tilemaps exported from [Sprite Fusion](https://www.spritefusion.com/).
44 lines
959 B
Dart
44 lines
959 B
Dart
import 'dart:async';
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame_sprite_fusion/flame_sprite_fusion.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
void main() {
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
class MyApp extends StatelessWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: GameWidget.controlled(
|
|
gameFactory: () => PlatformerGame(
|
|
camera: CameraComponent.withFixedResolution(width: 320, height: 180),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class PlatformerGame extends FlameGame {
|
|
PlatformerGame({super.camera});
|
|
|
|
@override
|
|
Color backgroundColor() => Colors.white70;
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
final map = await SpriteFusionTilemapComponent.load(
|
|
mapJsonFile: 'map.json',
|
|
spriteSheetFile: 'spritesheet.png',
|
|
);
|
|
await world.add(map);
|
|
|
|
camera.moveTo(map.size * 0.5);
|
|
}
|
|
}
|