ECS-friendly ldtk plugin for bevy, leveraging bevy_ecs_tilemap

Overview

bevy_ecs_ldtk

An ECS-friendly ldtk plugin for bevy. Uses bevy_ecs_tilemap as a base. Not released yet, still in development.

screenshot

bevy_ecs_tilemap once supported ldtk loading, but this was removed to keep the plugin small and focused (see: https://github.com/StarArawn/bevy_ecs_tilemap/issues/84).

This plugin aims to be a more complete solution to ldtk in bevy, with the following goals.

  • Supports all layer types
    • tile layers
      • rendered with bevy_ecs_tilemap
    • auto tile layers
      • rendered with bevy_ecs_tilemap
    • intgrid layers
      • intgrid values accessible as components on tiles
    • entity layers
      • new entities spawned at the correct location for users to flesh out in their own systems
      • fields accessible from components on new entities
  • support for external levels
  • hot-reloading for ldtk and its dependencies
    • hot-reloading for tile layers
    • hot-reloading for auto tile layers
    • hot-reloading for intgrid layers
    • hot-reloading for entity layers
    • hot-reloading for tilesets
    • hot-reloading for external levels (see: https://github.com/Trouv/bevy_ecs_ldtk/issues/1)
  • derive macros for registering bundles to spawn for specific intgrid-layer and entity-layer values
  • support for optionally loading level-neighbors

Once most of these goals are met, and bevy has reached 0.6, this crate will have its first release.

Comments
  • Migrated to bevy 0.9

    Migrated to bevy 0.9

    Does not apply to the platformer example (rapier2d) because we are waiting on https://github.com/dimforge/bevy_rapier/pull/272. When that PR is merged I will update this.

    opened by greenfierydragon 7
  • refactor!: update to bevy 0.8 and bevy_ecs_tilemap rewrite

    refactor!: update to bevy 0.8 and bevy_ecs_tilemap rewrite

    Thanks to @nfagerlund for the help with the bevy 0.8 update and lots of troubleshooting.

    There's a couple extra major changes here worth pointing out

    • no more batch spawning, bevy_ecs_tilemap doesn't really support it in the rewrite. This will probably allow us to simplify the level spawning code, but for now it works.
    • all tiles have SpatialBundles and are all children of layer entities. Before, this was only true for tiles with intgrid values and metadata. This helps with despawning levels, but it also makes the hierarchy a little less confusing. It does compromise some performance though, since potentially thousands of entities will now have components that they didn't have before.
    opened by Trouv 7
  • When change `LevelSpawnBehavior::UseZeroTranslation` to `LevelSpawnBehavior:: UseWorldTranslation{load_level_neighbors: true,}` all collision positions shifting

    When change `LevelSpawnBehavior::UseZeroTranslation` to `LevelSpawnBehavior:: UseWorldTranslation{load_level_neighbors: true,}` all collision positions shifting

    Hi. During your example platformer I tried to make the same logic for my own game. But when I've changed LevelSpawnBehaviour::UseZeroTranslation to

    LevelSpawnBehavior::{
      load_level_neighbors: true,
    }
    

    Before that, all collisions work fine, and the game is 100% legit. But after changing the config all collisions took the wrong position and were placed at the same place as it was for UseZeroTranslation. The same problem with the Ladder collision. When I change the config all collisions for entities also shift.

    Do you face that problem during your platformer example? If yes, how to deal with it?

    opened by MadMed677 7
  • Access tile data

    Access tile data

    Hi,

    Ldtk makes it possible to link data to tiles of a tile-set (either arbitrary text or enum-based)

    It would be nice if there was a TileData(or equivalent) component inserted on tiles that have data defined so that we could query them and have logic based on the data we defined in ldtk.

    enhancement 
    opened by jcornaz 6
  • With attribute

    With attribute

    Summary

    Adds a new attribute to the LdtkEntity derive macro named with. It allows for bundles to implement custom initializers using a method. This macro takes in a scoped function with signature (e: EntityInstance) -> T where T is the field type.

    Example

    pub struct Bundle {
       #[with(foo_initializer)]
        foo: i32;
    }
    
    fn foo_initializer(_e: EntityInstance) -> i32 {
        4
    }
    
    Longer Example
    #[derive(Clone, Default, Bundle)]
    pub struct ColliderBundle {
        pub collider: Collider,
        pub rigid_body: RigidBody,
        pub damping: Damping,
        ...
    }
    
    #[derive(Bundle, Default, LdtkEntity)]
    pub struct PlayerBundle {
        player: Player,
        #[with(player_collider)]
        #[bundle]
        collider: ColliderBundle,
    }
    
    fn player_collider(_: EntityInstance) -> ColliderBundle {
        ColliderBundle {
            collider: Collider::capsule(Vec2::new(0., -4.), Vec2::new(0., -12.), 5.),
            rigid_body: RigidBody::Dynamic,
            rotation_constraints: LockedAxes::ROTATION_LOCKED,
            damping: Damping {
                linear_damping: 10.0,
                ..Default::default()
            },
            ..Default::default()
        }
    }
    

    Issue

    The same functionality can be done using from_entity_instance by filtering the identifier to the correct type. However, this could cause function bloat when many entities with different identifiers implement the same bundle. You can have cleaner and safer code separation with this with(function) attribute.

    ToDo

    • [ ] Ensure type safety of function return; the error messages aren't very good if the function doesn't return the correct type
    opened by marcoseiza 5
  • Critical Memory Leak and Segfault when Using Autolayers

    Critical Memory Leak and Segfault when Using Autolayers

    When running a demo map with auto-layers on Linux Ubuntu 20.04 I'm getting a memory leak that will rapidly expand to using 8GB+ of memory in less than 30 seconds before finally segfaulting.

    There's nothing obvious in the logs other than the fact that it happens immediately after LDtk asset creation detected. and nothing happens after that.

    demo-map.zip trace_log.txt

    bug 
    opened by zicklag 5
  • feat: add `Respawn` component and rework schedule using it

    feat: add `Respawn` component and rework schedule using it

    Closes #96 Closes #108

    This is a pretty major change internally. If you're reading this and want to help me out, please update your games to this branch and let me know here whether or not there are any issues. I would like this to be the final PR before releasing 0.4, and I would like to release 0.4 very soon.

    bevy_ecs_ldtk = { git = "https://github.com/Trouv/bevy_ecs_ldtk", branch = "feat/respawn" }
    

    The scheduling has been completely reworked, and some systems have been significantly changed as a result. However, this is definitely an improvement. Many frame-delay issues are addressed by this rework, and hot reloading works again. This change was assisted by a new Respawn component, which can work on world entities and level entities. As a bonus, users can use the Respawn component in their games. I imagine this will mostly be used to restart levels.

    The main point of this rework is to be more careful about having stage separation between commands-sensitive, order-sensitive systems. If one adds a particular component to entities, and another filters for those additions, there needs to be a stage barrier between them. Most importantly, if one despawns entities, and another spawns similar entities, there needs to be stage barrier between them. This last point was the main cause for a lot of bugs since updating to 0.8 and the bevy_ecs_tilemap rewrite.

    One drawback here is that there's a new stage between update and post-update: LdtkStage::Clean. It's important that this goes before PostUpdate, since it despawns bevy_ecs_tilemap entities, which need to be further cleaned up in PostUpdate. It's also important that this goes after Update so that users can use Respawn and Worldly components without experiencing frame-delay or undefined behavior, and without having to worry about doing anything special with their scheduling. This isn't ideal, but I think it's a small price to pay. Besides, stageless is just around the corner.

    Use cases targeted

    • Spawning LdtkWorldBundle in startup system
      • Selecting levels with LevelSelection
      • Selecting levels with LevelSet
    • Spawning LdtkWorldBundle in non-startup system (State::on_enter)
      • Selecting levels with LevelSelection
      • Selecting levels with LevelSet
    • Spawning LdtkWorldBundle with an already-loaded LdtkAsset handle
    • Hot reloading levels
    • Respawning world with Respawn component
    • Respawning level with Respawn component

    New schedule (updated c5984fded3e875a42d9daa1e238b3ad964ac8a7a)

    • Stage PreUpdate
      • LdtkAsset processor system
        • Reads AssetEvent::Modified and adds Respawn components to entities with those handles
      • level spawn system
        • For any new placeholder level entities, or any that have Respawn components, spawn their contents normally
    • Stage LdtkStage::ProcessApi (between update and post update)
      • worldly adoption system
        • Have the grandparents of worldly entities adopt them (no change)
        • Needs to be after Update for frame delay reasons
      • LevelSelection system
        • Updates LevelSet components according to LevelSelection values
        • Needs to be after Update and before the LevelSet system for frame delay reasons
      • LevelSet system
        • For any world entities whose LevelSets have changed, or that have Respawn components, spawn/despawn placeholder level entities as children accordingly
      • Respawn cleanup system
        • Exclusive system at the end of the stage
        • For Handle<LdtkAsset> entities with Respawn components, despawns all of their children with Worldly or Handle<LdtkLevel> components
        • For Handle<LdtkLevel> entities with Respawncomponents, despawns their descendants.
        • Needs to be after the LevelSet system for frame delay reasons, but before PostUpdate to appease bevy_ecs_tilemap cleanup

    Known issues (to be fixed or promoted)

    • When using Respawn on a world where a Worldly entity has the only handle to a particular asset via #[sprite_bundle(...)], that asset unloads.
    opened by Trouv 5
  • A little bit of help on the refactor/tilemap-rewrite branch

    A little bit of help on the refactor/tilemap-rewrite branch

    I moved the Bevy dependency to 0.8 and the bevy_ecs_tilemap one to 0.7, then started looking for whatever broke.

    ~This isn't a complete upgrade and it isn't in proper working condition (the examples still need a Heron bump that isn't out yet, and also I'm still trying to untangle whatever's going on with inherited visibility), but it IS building. And all these changes seem to be things you'd have needed to do anyway, so maybe it'll save you a couple steps.~

    This seems to be mostly in proper working order at this point, but the examples (except basic) still need updates, including a Heron upgrade that I think isn't out yet. There's also some outstanding cleanup that needs done and warnings that need dealt w/, which you probably already knew about.

    opened by nfagerlund 5
  • WASM not rendering the map

    WASM not rendering the map

    I made a simple game, and when I run the binary build the map loads just fine, but when I build for WASM it doesn't show the map/level

    not sure if it's a misconfiguration on my part,

    Idk what info do you need to see if it's an actual problem,

    but I will leave my repo here

    and feel free to ask me anything

    (I'm refreshing the page here)

    scrnli_7_23_2022_3-39-03 PM.webm

    opened by BKSalman 5
  • Optional level background color

    Optional level background color

    I've been working on a test project with LDtk, and I've noticed that equal colors that match in LDtk do not match when running in bevy. The level background (above the floor) and clear color (below the floor) in this screenshot are both equal to #0D2B45, but when rendered in engine they don't match. Ideally of course, they would match, but I would also be happy with being able to turn off level backgrounds rendering which could allow me to do my own parallax effects for a background in future.

    image

    enhancement good first issue 
    opened by jakemcleman 5
  • Upgrade `bevy_ecs_tilemap` to 0.8

    Upgrade `bevy_ecs_tilemap` to 0.8

    I made minimal changes to the code to make it compile.

    I assume TilemapTexture::Single is equivalent to the TilemapTexture behaviour from 0.7.

    Closes https://github.com/Trouv/bevy_ecs_ldtk/issues/121

    opened by bardt 4
  • refactor: change #[from_entity_instance] to use references

    refactor: change #[from_entity_instance] to use references

    EntityInstance is a rather large struct, and cloning it requires allocating for several fields. Despite this fact, each use of the #[from_entity_instance] attribute was cloning the struct once, wasting CPU time for no good reason - especially for Bundles that contain several #[from_entity_instance] fields.

    Change the attribute to work on From<&EntityInstance> instead of From, avoiding the implicit clone in most cases. The clone is still necessary when a plain EntityInstance field exists in a struct deriving LdtkEntity, which is handled by having EntityInstance implement From<&EntityInstance>.

    While being a breaking change, fixing up users should be trivial - in most cases no owned EntityInstance is needed at all, and where it is an explicit clone can be inserted.

    opened by NeoRaider 0
  • Example manipulating tiles, layers and levels?

    Example manipulating tiles, layers and levels?

    I can't seem to figure out how to manipulate(or add) a specific tile in a specific layer and level.

    The best option I found so far for changing a tiles texture to another is to Query TileStorage but there's no way to know which layer or level the storage references.

    It would be very helpful with small examples showing basic manipulation/adding etc.

    opened by jruiss 1
  • chore(main): release 0.6.0

    chore(main): release 0.6.0

    opened by github-actions[bot] 0
  • Made pivot the new location of entities spawned in the world

    Made pivot the new location of entities spawned in the world

    The size of the visual area for an entity should only be an indicator to the user about how big it will seem, changing the size should not change where the entity spawned.

    This change is how it works in most other engines I've seen deal with it, and I believe it's better to have a defined point which can be seen in the editor to represent the translation of the entity, rather than arbitrarily moving them half way up their visual area.

    opened by mckahz 11
  • Fix levels having incorrect `GlobalTransform` the first frame

    Fix levels having incorrect `GlobalTransform` the first frame

    The transform propagation system runs in the PostUpdate stage, so spawn the levels before PostUpdate so they have time to propagate, but after ProcessApi, so they'll be ready the next frame (assuming the LdtkWorldBundle will be spawned during the Update) stage.

    I ran into this bug because in my game I scale the levels, and collision detection is therefore way off during the first frame sending my player character flying.

    opened by johanhelsing 1
Releases(v0.5.0)
  • v0.5.0(Nov 20, 2022)

    0.5.0 (2022-11-19)

    ⚠ BREAKING CHANGES

    • upgrade to bevy 0.9 (#138) (thanks @greenfierydragon)
    • adjust tile transformations for bevy_ecs_tilemap 0.8 (#136)
    • upgrade bevy_ecs_tilemap dependency to 0.8 (#134) (thanks @bardt)

    Features

    • add with attribute to LdtkEntity derive (#128) (18e84be) (thanks @marcoseiza)
    • insert Name component on ldtk entities, layers, and levels (33f2b73) (thanks @Piturnah)
    • upgrade bevy_ecs_tilemap dependency to 0.8 (#134) (7d4d1d0)
    • upgrade to bevy 0.9 (#138) (048285c)

    Bug Fixes

    • adjust tile transformations for bevy_ecs_tilemap 0.8 (#136) (aad0325)
    • do not spawn empty ECS entity for omitted worldly entities (#122) (a9a0318) (thanks @NeoRaider)
    • filter out out-of-bounds tiles (#129) (37dfed0) (thanks for the report @zicklag)

    Other Changes

    • refactor platformer example to use bevy_rapier2d (#127) (thanks @CashWasabi)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Aug 17, 2022)

    New features:

    • New LayerMetadata component, automatically added to AutoTile, Tile and IntGrid layers #102
    • New Respawn component that you can add to world entities or level entities to respawn them (thanks for the suggestion @bardt) #109
    • #[sprite_sheet_bundle] attribute macro now supports LDtk "tileset padding" #110

    Breaking changes:

    • Spelling of LevelBackground::Nonexistent fixed (thanks @johanhelsing) #83
    • offset argument added to #[sprite_sheet_bundle(...)] attribute macro #110

    Bug fixes:

    • Support multilines string type (thanks @jrasanen) #90
    • COPY_SRC no longer added to modified textures recursively (thanks for the report @oliverbestmann) #98
    • Level no longer spawns twice when spawning LdtkWorldBundle in a non-startup system (thanks for the report @grace125, @beardedmullett, @chungwong) #109

    Other:

    • Updated to bevy 0.8 (thanks @nfagerlund) #104
    • Schedule completely reworked. Fewer frame delays + more correct LevelSelection/LevelSet behavior #109
    • New stage LdtkStage::ProcessApi as part of the schedule rework. #109
    • Implement ground detection in platformer example (thanks @ChristopherBiscardi) #86
    • Reflect derived for all components, improving bevy-inspector-egui integration (thanks @johanhelsing) #84
    • Clone derived for LdtkAsset (thanks @jrasanen) #90
    • All tiles have SpatialBundles and are children of layer entities, as opposed to just those with intgrid values and metadata #106
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Apr 25, 2022)

    New features:

    1. LDtk 1.1 support #75
    2. LdtkSettings::set_clear_color now an enum with an additional option: FromLevelBackground #76
    3. Level background rendering now optional via LdtkSettings::level_background option #76
    4. Intgrid color rendering now optional via LdtkSettings::int_grid_rendering option #76
    5. Layer opacity support #77
    6. Level background image support #78
    7. Support for tileset custom data/enum tagging via TileMetadata and TileEnumTags components #80
    8. Bevy 0.7 support #81

    Breaking changes:

    1. LdtkSettings refactor, changed structure of existing options to use enums instead of bools, with load_level_neighbors being an option within LevelSpawnBehavior::UseWorldTranslation #76
    2. The utils coordinate conversion functions have been rewritten significantly to improve their utility and organization. See PR for more details #80

    Bug fixes:

    1. Auto-tiled IntGrid layer missing GridCoords for unset tiles (thanks for the reports @NeoRaider) #62

    Other:

    1. Added link to LDtk in readme/docs (thanks @pard68) #66
    2. Added #[from_entity_instance] demonstration to platformer example (thanks @chungwong) #74
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Feb 25, 2022)

    New features:

    • GridCoords component which is added to all tiles, and can be added to LdtkEntitys with the #[grid_coords] attribute: #55
    • Colors! Now bevy_ecs_ldtk uses LDtk's workspace background color, level background colors, and IntGrid tile colors! #59
    • Wasm support through the "atlas" feature: #54 (thanks @colathro)

    Bug fixes:

    • LdtkEntity and LdtkIntCell now work better on generic bundles: #53
    • Tile spacing supported again via the "atlas" feature: #56
    • No more chatty bevy_ecs_tilemap warnings regarding COPY_SRC textures: #59

    Other changes:

    • Platformer example now spawns fewer colliders: #55
    • Constructors used by LdtkEntity are now more specific #58
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Jan 16, 2022)

Owner
Trevor Lovell
Game dev and math nerd, currently working as a performance SDET.
Trevor Lovell
Inverse kinematics plugin for Bevy implementing the FABRIK algorithm.

Inverse kinematics plugin for Bevy implementing the FABRIK algorithm.

Georg Friedrich Schuppe 11 Dec 31, 2022
A example bevy application using bevy-kajiya for its renderer

☀️ bevy-kajiya playground A example bevy application using bevy-kajiya for its renderer NOTE: only tested on Windows. For more context, check out the

Sebastian Hamel 20 Dec 5, 2022
qn (quick note) is a simple, fast and user-friendly way to save notes 🦀⚙️

Quick Note qn Install This is currently for my personal use. I may push breaking changes at any time. If you want to use it, bring down the code and r

Code Smell 3 Jul 15, 2022
Provides a Suricata Eve output for Kafka with Suricate Eve plugin

Suricata Eve Kafka Output Plugin for Suricata 6.0.x This plugin provides a Suricata Eve output for Kafka. Base on suricata-redis-output: https://githu

Center 7 Dec 15, 2022
A powerful minecraft bedrock software written in Rust with a powerful Typescript plugin API.

Netrex A powerful minecraft bedrock software written in RustLang. Why Netrex? It's written in Rust. Unique and straight to the point. Typescript Plugi

Netrex 51 Dec 26, 2022
An example Kibana plugin written in Rust and Typescript

An example Kibana plugin written in Rust and Typescript

Aleh Zasypkin 3 Dec 24, 2022
A collection of exponentially-smoothed camera controllers for the Bevy Engine.

smooth-bevy-cameras A collection of exponentially-smoothed camera controllers for the Bevy Engine. Look Transform All controllers are based on a LookT

Duncan 122 Dec 24, 2022
An ability / resource / cooldown management library for Bevy.

About leafwing-abilities is an opinionated, ready-to-use Bevy library and plugin for handling abilities. It features: cooldown tracking resource manag

null 2 Mar 30, 2022
Easier joystick, mouse and keyboard input handling in Bevy

Easier joystick, mouse and keyboard input handling in Bevy

Pedro Henrique 31 Dec 20, 2022
Here are a few cargo-generate templates for use when creating bevy applications

Bevy-template-rs Here are a few cargo-generate templates for use when creating bevy applications. Templates Game This is a template for starting a new

Johnny Tidemand Vestergaard 19 Nov 4, 2022
Composable Alternatives to Bevy's RunCriteria, States, FixedTimestep

Composable Alternatives to Bevy's RunCriteria, States, FixedTimestep This crate offers alternatives to the Run Criteria, States, and FixedTimestep sch

null 221 Jan 2, 2023
A Bevy plugin for loading the LDtk 2D tile map format.

bevy_ldtk ( Tileset from "Cavernas" by Adam Saltsman ) A Bevy plugin for loading LDtk tile maps. Usage use bevy::prelude::*; use bevy_ldtk::*; fn mai

Katharos Technology 23 Jul 4, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
A tilemap rendering crate for bevy which is more ECS friendly.

bevy_ecs_tilemap A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile. Features A tile per entity Fast renderin

John 414 Dec 30, 2022
wecs (wckd-ecs) is a simple ECS library suitable for general use.

wecs wecs (wckd-ecs) is a simple ECS library heavily based on bevy_ecs. Motivation As part of my "Road to Rust GameDev" journey, I wanted to learn how

João Victor 9 Jul 2, 2023
An extension to the bevy_ecs_tilemap, allowing for configurable tilesets, auto tiling, and more

bevy_ecs_tilemap_tileset A mouthful, I know. Working on a better name. An extension to the wonderful bevy_ecs_tilemap crate for Bevy, allowing for con

null 40 Dec 12, 2022
Compatability between `bevy_mod_picking` and `bevy_ecs_tilemap`

bevy_picking_tilemap Provides a bevy_mod_picking backend to add integration with bevy_ecs_tilemap, enabling individual Tile entities to receive the pi

null 4 Apr 9, 2024
Ethereum transaction simulator leveraging Foundry's codebase

Enso Transaction ?? Simulator ?? A simple API which simulates a given transaction request. ?? API ?? POST /api/v1/simulate Simulates a single transact

null 162 Jun 4, 2023
Tools to use Axon Server with rust, by leveraging Synapse.

Axon Rust This contains a Axon Synapse rust client, based on the open api generated code. For now, we didn't publish this crate, to forking this proje

AxonIQ 6 Oct 22, 2023
Schemars is a high-performance Python serialization library, leveraging Rust and PyO3 for efficient handling of complex objects

Schemars Introduction Schemars is a Python package, written in Rust and leveraging PyO3, designed for efficient and flexible serialization of Python c

Michael Gendy 7 Nov 21, 2023