LDtk Rust Library

Crates.io Docs.rs

ldtk_rust enables access to LDtk data for use in Rust. LDtk is a 2D level editor for games that supports multiple tile layers, powerful auto-tiling rules, entity placement and more.

Status

This library works with LDtk version 0.7.0 and supports the optional external level files. LDtk updates save files automatically, so there's no reason to be on an older version, but if you are you should use v0.2.0 of this library.

Getting Started

Calling the new() method on the LdtkFile struct with the path to a LDtk file will populate a struct that closely resembles the LDtk JSON format.

```rust use ldtk_rust::Project;

fn main() { let filepath = "assets/testgame.ldtk".tostring(); let ldtk = Project::new(filepath); println!("First level pixel height is {}!", ldtk.levels[0].px_hei); } ```

Your editor's auto-complete should help you visualize your options, or you can generate API docs with "cargo doc --open" or view them here.

Run the Examples

You can run the programs in the example folder using cargo:

```bash

cargo run --example basic ```

Example dependencies do not load when compiling the library for production.

Using in a Real Game

An example running in Bevy Engine is included in the examples directory. There are lots of comments, and the focus of the example is on the process, not the Bevy-specific code. If you are using another game engine the example will hopefully still be understandable and useful.

Please note if you are using Bevy and you have more than one tileset referenced in LDtk, you may have intermittent issues due to issue 1056.

Implementation Details

Other Options