mirror of
https://github.com/flame-engine/flame.git
synced 2025-11-02 20:13:50 +08:00
Enable DCM rule double-literal-format. More details [here](https://dcm.dev/docs/rules/common/double-literal-format/). This both forbids trailing zeroes and mandates leading zeroes. If we would prefer a different style (e.g. prefer no leading zero instead), just lmk :)
66 lines
1.7 KiB
Dart
66 lines
1.7 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/effects.dart';
|
|
import 'package:flame/flame.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame_tiled/flame_tiled.dart';
|
|
import 'package:flutter/widgets.dart' hide Animation, Image;
|
|
|
|
void main() {
|
|
runApp(GameWidget(game: TiledGame()));
|
|
}
|
|
|
|
class TiledGame extends FlameGame {
|
|
late TiledComponent mapComponent;
|
|
|
|
TiledGame()
|
|
: super(
|
|
camera: CameraComponent.withFixedResolution(
|
|
width: 16 * 28,
|
|
height: 16 * 14,
|
|
),
|
|
);
|
|
|
|
@override
|
|
Future<void> onLoad() async {
|
|
camera.viewfinder
|
|
..zoom = 0.5
|
|
..anchor = Anchor.topLeft
|
|
..add(
|
|
MoveToEffect(
|
|
Vector2(1000, 0),
|
|
EffectController(
|
|
duration: 10,
|
|
alternate: true,
|
|
infinite: true,
|
|
),
|
|
),
|
|
);
|
|
|
|
mapComponent = await TiledComponent.load('map.tmx', Vector2.all(16));
|
|
world.add(mapComponent);
|
|
|
|
final objectGroup =
|
|
mapComponent.tileMap.getLayer<ObjectGroup>('AnimatedCoins');
|
|
final coins = await Flame.images.load('coins.png');
|
|
|
|
// We are 100% sure that an object layer named `AnimatedCoins`
|
|
// exists in the example `map.tmx`.
|
|
for (final object in objectGroup!.objects) {
|
|
world.add(
|
|
SpriteAnimationComponent(
|
|
size: Vector2.all(20.0),
|
|
position: Vector2(object.x, object.y),
|
|
animation: SpriteAnimation.fromFrameData(
|
|
coins,
|
|
SpriteAnimationData.sequenced(
|
|
amount: 8,
|
|
stepTime: 0.15,
|
|
textureSize: Vector2.all(20),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}
|