A Bevy plugin for loading the LDtk 2D tile map format.

Overview

bevy_ldtk

Crates.io Docs.rs Katharos License

screenshot

( Tileset from "Cavernas" by Adam Saltsman )

A Bevy plugin for loading LDtk tile maps.

Usage

use bevy::prelude::*;
use bevy_ldtk::*;

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_plugin(LdtkPlugin)
        .add_startup_system(setup.system())
        .run();
}

fn setup(commands: &mut Commands, asset_server: Res<AssetServer>) {
    commands
        // Spawn a camera
        .spawn(Camera2dBundle::default())
        // Spawn a map bundle
        .spawn(LdtkMapBundle {
            // Specify the path to the map asset to load
            map: asset_server.load("map1.ldtk"),
            config: LdtkMapConfig {
                // Automatically set the clear color to the LDtk background color
                set_clear_color: true,
                // You can specify a scale or leave it set to 1 for 1 to 1 pixel size
                scale: 3.0,
                // Set which level to load out of the map or leave it to 0 for the default level
                level: 0,
                // Tell the map to center around it's `Transform` instead of putting the top-left
                // corner of the map at the origin `Transform`.
                center_map: true,
            },
            ..Default::default()
        });
}

Layers

When the map layers are spawned, the bottommost layer is spawned at the transform coordinate of the LdtkMapBundle's Transform component. Each layer after the bottom layer is placed one unit higher on the Z axis. To have your sprites for players, etc. appear on top of the rendered map, their Z axis translation must be higher than the map transform + the layer number that you want it to appear above.

Bevy Versions

Bevy Version Plugin Version
0.4 0.2, 0.3
master 0.3 with the bevy-unstable feature ( see below )

Using Bevy From Master

You can use this crate with Bevy master by adding a patch to your Cargo.toml and by adding the bevy-unstable feature to this crate:

[dependencies]
# Bevy version must be set to "0.4" and we will
# override it in the patch below.
bevy = "0.4"
bevy_ldtk = { version = "0.3", features = ["bevy-unstable"] }

[patch.crates-io]
bevy = { git = "https://github.com/bevyengine/bevy.git" }

Note that as Bevy master may or may not introduce breaking API changes, this crate may or may not compile when using the bevy-unstable feature.

Features

  • An efficient renderer that only uses 4 vertices per map layer and lays out tiles on the GPU
  • Supports hot reload through the Bevy asset server integration
  • Heavily commented code to help others who want to see how to make their own tilemap renderers.

Caveats

The plugin is in relatively early stages, but it is still rather functional for many basic maps

  • Many features are not supported yet:
    • multiple overlapping autotile tiles
    • tilemaps with spacing in them
    • levels in separate files
  • Occasionally some slight rendering artifacts between tiles. Not sure what causes those yet.

If you run into anything that isn't supported that you want to use in your game open an issue or PR to help prioritize what gets implemented.

License

Bevy LDtk is licensed under the Katharos License which places certain restrictions on what you are allowed to use it for. Please read and understand the terms before using Bevy LDtk for your project.

Comments
  • Use map data in systems

    Use map data in systems

    Hi :) How do I access the map from a system? I am new to bevy so I might have missed something. My first try was to use map: Query<LdtkMap> but that didnt work.

    Basicly I want to get from the map the entities to draw them as needed. And the required information is stored in the map.

    opened by MTRNord 20
  • Pixel Bleeding Between Tiles

    Pixel Bleeding Between Tiles

    On one map, which I unfortunately can't share because of non-free assets, has an issue when zooming in and out in the display_map example, where there will be a brief flash of bleeding pixels in between the tiles. I believe this is due to mipmapping or level of detail as it seems to be related to zooming in and out only and tends to be accompanied by a drop in frame rate.

    First we need to get a map to re-produce with and second we need to figure out what's causing the issue.

    bug help wanted 
    opened by zicklag 6
  • webgl not supported

    webgl not supported

    It looks like this library can't run on webgl due to something with the shaders. I know this library is not supported anymore officially, but I'm wondering if there is a way to support webgl with this library. Happy to contribute a fix, just need some guidance.

    opened by gzzo 5
  • Make it work with bevy 0.5

    Make it work with bevy 0.5

    Thank you for this library. Hope this is helpful. I wasn't sure if you wanted to try to keep the special configuration attributes in place for the transition to 0.5 or not. I removed them in my branch.

    opened by iarebatman 3
  • Properly Handle Overlapping Auto-tiles in the Same Cell

    Properly Handle Overlapping Auto-tiles in the Same Cell

    It is possible for there to be multiple auto-tiles overlayed in the same cell of an LDtk layer. This is not currently handled correctly and causes some trouble for us because of the way that we spawn one chunk per LDtk layer. We are going to have fix this in order to properly display many LDtk maps:

    image

    opened by zicklag 2
  • ldtk_rust 0.4.0 (ldtk 0.8.1) support

    ldtk_rust 0.4.0 (ldtk 0.8.1) support

    Hello.

    I'm new to the ldtk & bevy world, but i noticed that i couldn't parse maps created with ldtk 0.8.1 so i made some patches in order to make it work. There isn't an official release of ldtk_rust 0.4.0, but there is a tag on their github and master supports 0.8.1, so i am using that for now.

    I see there is some issue with the "both flip", but i'm not sure if/how it worked before so maybe you can hint. Colors seem to be weird as well, although i'm not sure if this is a problem with my patch or me not setting a proper background with bevy?

    See rendered in bevy: image

    Versus in ldtk: image

    Maybe this will be useful once it is actually released, if not feel free to close!

    Thanks!

    opened by linde12 2
  • Make All LDtk Sample Maps Render

    Make All LDtk Sample Maps Render

    For the sake of this issue we are just counting that the map renders the default level correctly, not counting issues caused by multi-file map loading or multiple levels.

    • [x] AutoLayers_1_basic.ldtk
    • [x] AutoLayers_2_stamps.ldtk
    • [x] AutoLayers_3_Mosaic.ldtk
    • [ ] AutoLayers_4_Advanced.ldtk
    • [x] Entities.ldtk
    • [ ] Test_file_for_API_showing_all_features.ldtk
    • [x] Typical_2D_platformer_example.ldtk
    • [x] Typical_TopDown_example.ldtk
    • [x] WorldMap_Free_layout.ldtk
    • [x] WorldMap_GridVania_layout.ldtk

    Out of scope for this issue:

    • SeparateLevelFiles.ldtk
    opened by zicklag 1
Owner
Katharos Technology
Pure Innovation
Katharos Technology
Bevy plugin helping with asset loading and organisation

Bevy asset loader This Bevy plugin reduces boilerplate when loading game assets. The crate offers the AssetCollection trait and can automatically load

Niklas Eicker 205 Jan 2, 2023
A simple camera for properly displaying tile-based low resolution pixel perfect 2D games in bevy.

Bevy Tiled Camera A simple camera for properly displaying low resolution pixel perfect 2D games in bevy. The camera will adjust the viewport to scale

sark 10 Oct 5, 2022
A framework for saving and loading game state in Bevy.

Bevy_save A framework for saving and loading game state in Bevy. Features bevy_save is primarily built around extension traits to Bevy's World. Serial

Hank Jordan 10 Jan 24, 2023
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
Quake .map files for the Bevy game engine.

Qevy A plugin that adds Quake .map file support for the Bevy game engine Supported Bevy Versions: 0.12 Supported Physics Engines: XPBD (Rapier coming

Brian Howard 8 Nov 12, 2023
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Jakob Hellermann 517 Dec 31, 2022
A plugin for Egui integration into Bevy

bevy_egui This crate provides a Egui integration for the Bevy game engine. Features: Desktop and web (bevy_webgl2) platforms support Clipboard (web su

Vladyslav Batyrenko 453 Jan 3, 2023
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

null 79 Nov 2, 2022
A Bevy plugin to use Kira for game audio

Bevy Kira audio This bevy plugin is intended to try integrating Kira into Bevy. The end goal would be to replace or update bevy_audio, if Kira turns o

Niklas Eicker 172 Jan 5, 2023
A prototype plugin providing a simple line drawing api for bevy.

bevy_debug_lines A prototype plugin providing a simple line drawing api for bevy. See docs.rs for documentation. Expect breakage on master. Click on t

Michael Palmos 92 Dec 31, 2022
A sprite-sheet animation plugin for bevy

Benimator A sprite sheet animation plugin for bevy Features A SpriteSheetAnimation component to automatically update the indices of the TextureAtlasSp

Jonathan Cornaz 140 Dec 27, 2022
A Bevy Engine plugin for making 2D paths, smooth animations with Bezier curves

bevy_pen_tool A Bevy Engine plugin for making 2D paths and smooth animations with Bezier curves TODO: Mesh-making functionality for building 2D shapes

Eli 36 Dec 22, 2022
A procedural sky plugin for bevy

bevy_atmosphere A procedural sky plugin for bevy Example use bevy::prelude::*; use bevy_atmosphere::*; fn main() { App::build() .insert_re

Jonah Henriksson 137 Dec 23, 2022
Generic cellular automaton plugin for bevy.

Bevy Cellular Automaton bevy_life is a generic plugin for cellular automaton. From the classic 2D Conway's game of life to WireWorld and 3D rules, the

Félix Lescaudey de Maneville 34 Nov 23, 2022
Verlet physics plugin for bevy.

bevy_verlet Simple Verlet points and sticks implementation for bevy. Features You can simply add a VerletPoint component on any entity with a Transfor

Félix Lescaudey de Maneville 34 Dec 9, 2022
Bevy plugin for an AssetServer that can load embedded resources, or use other AssetServers based on the path.

Bevy-Embasset Embed your asset folder inside your binary. bevy-embasset adds support for loading assets embedded into the binary. Furthermore, it can

Johnny Tidemand Vestergaard 9 Aug 4, 2022
Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

Jerome Humbert 256 Dec 30, 2022
A plugin to use the kajiya renderer with bevy

??️ ?? bevy-kajiya A plugin that enables use of the kajiya renderer in bevy WARNING: This plugin is barebones and supports a limited set of features.

Sebastian Hamel 79 Jan 5, 2023
Tweening animation plugin for the Bevy game engine.

?? Bevy Tweening Tweening animation plugin for the Bevy game engine. Features Animate any field of any component or asset, including custom ones. Run

Jerome Humbert 135 Dec 23, 2022