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

outdated

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/animation.dart';
import 'package:flame/components/animation_component.dart';
import 'package:flame/flame.dart';
import 'package:flame/game.dart';
import 'package:flutter/widgets.dart' hide Animation;
import 'package:tiled/tiled.dart' show ObjectGroup, TmxObject;
import 'package:flame_tiled/flame_tiled.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  Flame.images.load('coins.png');
  final TiledGame game = TiledGame();
  runApp(game.widget);
}

class TiledGame extends BaseGame {
  TiledGame() {
    final TiledComponent tiledMap = TiledComponent('map.tmx', Size(16.0, 16.0));
    add(tiledMap);
    _addCoinsInMap(tiledMap);
  }

  void _addCoinsInMap(TiledComponent tiledMap) async {
    final ObjectGroup objGroup =
        await tiledMap.getObjectGroupFromLayer("AnimatedCoins");
    if (objGroup == null) {
      return;
    }
    objGroup.tmxObjects.forEach((TmxObject obj) {
      final comp = AnimationComponent(
        20.0,
        20.0,
        Animation.sequenced(
          'coins.png',
          8,
          textureWidth: 20,
          textureHeight: 20,
        ),
      );
      comp.x = obj.x.toDouble();
      comp.y = obj.y.toDouble();
      add(comp);
    });
  }
}
53
likes
30
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.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flame, flutter, tiled

More

Packages that depend on flame_tiled