flame_tiled 1.12.0 copy "flame_tiled: ^1.12.0" to clipboard
flame_tiled: ^1.12.0 copied to clipboard

Tiled support for the Flame game engine. This uses the tiled package and provides wrappers and components to be used inside Flame.

example/lib/main.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;

  final world = World();
  late final CameraComponent cameraComponent;

  @override
  Future<void> onLoad() async {
    cameraComponent = CameraComponent.withFixedResolution(
      world: world,
      width: 16 * 28,
      height: 16 * 14,
    );
    cameraComponent.viewfinder.zoom = 0.5;
    cameraComponent.viewfinder.anchor = Anchor.topLeft;
    cameraComponent.viewfinder.add(
      MoveToEffect(
        Vector2(1000, 0),
        EffectController(
          duration: 10,
          alternate: true,
          infinite: true,
        ),
      ),
    );

    addAll([cameraComponent, world]);

    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: .15,
              textureSize: Vector2.all(20),
            ),
          ),
        ),
      );
    }
  }
}
53
likes
0
pub points
93%
popularity

Publisher

verified publisherflame-engine.org

Tiled support for the Flame game engine. This uses the tiled package and provides wrappers and components to be used inside Flame.

Homepage
Repository (GitHub)
View/report issues

Funding

Consider supporting this project:

opencollective.com
github.com
patreon.com

License

unknown (license)

Dependencies

collection, flame, flutter, meta, tiled, xml

More

Packages that depend on flame_tiled