Code Monkey home page Code Monkey logo

bevy_ecs_ldtk's Introduction

bevy_ecs_ldtk

crates.io docs.rs crates.io MIT/Apache 2.0 Bevy tracking CI

An ECS-friendly LDtk plugin for bevy. Uses bevy_ecs_tilemap as a base.

platformer-example

cargo run --example platformer --release

Features

  • Support for all layer types
  • Support for loading external levels
  • Hot reloading (requires double-saving for external levels)
  • Solutions for easily loading/unloading levels, changing levels, loading level neighbors...
  • Low-boilerplate solutions for spawning bundles for LDtk Entities and IntGrid tiles using derive macros (other options available)
  • serde types for LDtk based off LDtk's QuickType loader, but with several QoL improvements
  • Support for Wasm (and tile spacing) through "atlas" feature

Getting Started

The goal of this plugin is to make it as easy as possible to use LDtk with bevy for common use cases, while providing solutions to handle more difficult cases. You only need a few things to get started:

  1. Add the LdtkPlugin to the App
  2. Insert the LevelSelection resource into the App to pick your level
  3. Spawn an LdtkWorldBundle
  4. Optionally, use #[derive(LdtkEntity)] and #[derive(LdtkIntCell)] on bundles and register them to the App to automatically spawn those bundles on Entity and IntGrid layers.
use bevy::prelude::*;
use bevy_ecs_ldtk::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(LdtkPlugin)
        .add_startup_system(setup)
        .insert_resource(LevelSelection::Index(0))
        .register_ldtk_entity::<MyBundle>("MyEntityIdentifier")
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());

    commands.spawn(LdtkWorldBundle {
        ldtk_handle: asset_server.load("my_project.ldtk"),
        ..Default::default()
    });
}

#[derive(Bundle, LdtkEntity)]
pub struct MyBundle {
    a: ComponentA,
    b: ComponentB,
    #[sprite_sheet_bundle]
    #[bundle]
    sprite_bundle: SpriteSheetBundle,
}

There are other attributes available to #[derive(LdtkEntity)] and #[derive(LdtkIntCell)], see the documentation for more details.

By default, LDtk Entities and IntGrid tiles get spawned with EntityInstance and IntGridCell components respectfully. So, you can flesh out these entities in a system that queries for Added<EntityInstance> or Added<IntGridCell> if you need more access to the world, or if you just don't want to use the LdtkEntity and LdtkIntCell traits.

To load a new level, you can just update the LevelSelection resource. Be sure to check out the LdtkSettings resource and the LevelSet component for additional level-loading options.

Compatibility

bevy bevy_ecs_tilemap LDtk bevy_ecs_ldtk
0.9 0.9 1.1 0.5
0.8 0.7 1.1 0.4
0.7 0.6 1.1 0.3
0.6 0.5 0.9 0.2
0.6 0.5 0.9 0.1

Asset Credits

bevy_ecs_ldtk's People

Contributors

trouv avatar nfagerlund avatar christopherbiscardi avatar johanhelsing avatar geieredgar avatar jrasanen avatar ispringle avatar neocturne avatar piturnah avatar janos-r avatar john-toohey avatar evenius avatar cashwasabi avatar marcoseiza avatar bardt avatar github-actions[bot] 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.