Coder Social home page Coder Social logo

bevy_ldtk's Introduction

Bevy LDtk

Crates.io Docs.rs Katharos License

A Bevy plugin for loading LDtk 2D tile maps.

screenshot

( Screenshot assets from the CanariPack 8BIT TopDown art pack by Johan Vinet )

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,
            },
            ..Default::default()
        });
}

Layers

Each layer in the loaded level is laid out in a quad one unit further away from the camera than the one before. This should allow you to put your character, etc. in the space between the layers to have some layers show in front of the character and the others show behind.

Running the Example

cargo run --example display_map

You can also copy your own LDtk maps into the assets folder and then run them by specifying the map file name and the level. For instance, this will load the second level from map2.ldtk:

cargo run --example display_map -- map2.ldtk 1

Bevy Versions

Bevy Version Plugin Version
0.4 0.2
master 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.2", 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

This plugin is in relatively early stages of development, and while it can load many basic maps, there are some caveats:

  • 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.

bevy_ldtk's People

Contributors

zicklag avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.