搜索插件、代码仓与 APP 分类

插件详情v0.12.0

tiled

一个 Dart Tiled 库。将您的 TMX 文件解析为有用的形式。与 Flame 兼容。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1.5万
喜欢数
33
Pub 分数
150

安装插件

flutter pub add tiled

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Tiled 包是一个 Dart 库,用于解析来自 Tiled 地图编辑器的 TMX 文件,并将其转换为游戏开发中可用的结构化数据。它与 Flame 游戏引擎无缝集成,使开发者能够跨多个平台高效地加载和渲染瓦片地图。该包支持 Tiled 的多种功能,如图层、对象和瓦片集,非常适合 2D 游戏。通过简洁直观的 API,它简化了地图集成过程,无需手动处理数据。

适合场景

  • 在游戏加载2D瓦片地图
  • 将 Tiled 地图与 Flame 引擎集成
  • 渲染分层游戏关卡
  • 处理来自 TMX 文件的碰撞对象
  • 构建平台游戏或解谜游戏

主要特点

  • 支持 TMX 文件解析
  • 与火焰游戏引擎兼容
  • 跨平台支持
  • 处理图块集和图层
  • 提供对象和碰撞数据

适合对象

  • 使用 Flame 的 2D 游戏开发者
  • Tiled 地图用户寻求 Dart 集成
  • 跨平台游戏项目
  • 独立游戏创作者
  • 游戏原型设计

使用建议

  • 需要 Tiled 地图文件,格式为 TMX
  • 仅限2D瓦片地图使用场景
  • 依赖 Flame 进行完整渲染
  • 不支持自定义 Tiled 插件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Tiled Dart

Pub cicd Discord

A Dart Tiled library.

Install from Dart Pub Repository

To include the package as a dependency in your pubspec.yaml, run the following (or add it manually):

dart pub add tiled

Usage

Import the package like this:

    import 'package:tiled/tiled.dart';
Load Tmx Files

Load a TMX file into a string by any means, and then pass the string to TiledMap.parseTmx():

    final String tmxBody = /* ... */;
    final TiledMap mapTmx = TiledMap.parseTmx(tmxBody);
Load Json Files

Alternatively load a json file with TiledMap.parseJson():

    final String jsonBody = /* ... */;
    final TiledMap mapJson = TiledMap.parseJson(jsonBody);
External Files

If your map references external files, like external tilesets (.tsx) or object templates (.tx), you have to pass one or more ParserProviders that resolve these files. Every time the parser encounters a reference to an external file, the first provider that canProvide the referenced path is asked for a Parser of its contents through getSource.

The path is always relative to the map file, also for files referenced from other external files, so a single provider can resolve any number of files, for example everything below a directory:

class DirectoryProvider extends ParserProvider {
  final String root;

  DirectoryProvider(this.root);

  @override
  bool canProvide(String path) => File('$root/$path').existsSync();

  @override
  Parser getSource(String path) {
    return Parser.fromString(File('$root/$path').readAsStringSync());
  }
}

Parser.fromString creates an XmlParser or a JsonParser depending on the contents. Every file is requested at most once per parsed map.

Objects that use a template inherit every value they do not specify themselves from the object of the template, and their gid is translated to the tilesets of the map. When the map does not contain the tileset of the template it is added to TiledMap.tilesets, like Tiled does when loading the map.

The providers are passed to parseTmx or parseJson:

    final TiledMap mapTmx = TiledMap.parseTmx(
      tmxBody,
      providers: [DirectoryProvider('assets/tiles')],
    );
Loading External Files Asynchronously

When the external files can only be loaded asynchronously, for example from an asset bundle, use TiledMap.fromString instead. It parses either tmx or json and loads every referenced file, also the ones referenced from other external files, with the given loader before returning the map:

    final TiledMap map = await TiledMap.fromString(
      contents,
      (path) => rootBundle.loadString('assets/tiles/$path'),
    );
Implementation

For further information and more usage examples, please take a look at the examples in flame_tiled.

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目