搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案