#bevy #ecs #tilemap #entity #tile #plugin

bevy_ecs_tilemap

A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile

5 releases (breaking)

Uses new Rust 2021

0.5.0 Jan 8, 2022
0.4.0 May 27, 2021
0.3.0 May 6, 2021
0.2.0 Apr 30, 2021
0.1.0 Apr 29, 2021
Download history 31/week @ 2021-10-06 27/week @ 2021-10-13 33/week @ 2021-10-20 14/week @ 2021-10-27 26/week @ 2021-11-03 17/week @ 2021-11-10 26/week @ 2021-11-17 24/week @ 2021-11-24 36/week @ 2021-12-01 46/week @ 2021-12-08 18/week @ 2021-12-15 17/week @ 2021-12-22 25/week @ 2021-12-29 100/week @ 2022-01-05 138/week @ 2022-01-12 95/week @ 2022-01-19

359 downloads per month
Used in bevy_ecs_ldtk

Custom license

130KB
2.5K SLoC

bevy_ecs_tilemap

Crates.io docs license Crates.io

A tilemap rendering plugin for bevy. It is more ECS friendly as it makes tiles entities.

Features

  • A tile per entity.
  • Fast rendering using a chunked approach.
  • Layers and sparse tile maps.
  • GPU powered animations.
  • Isometric and Hexagonal tile maps.
  • Initial support for Tiled file exports.

Upcoming Features

  • Support for isometric and hexagon rendering.
  • Built in animation support – see animation example.
  • Texture array support.
  • Layers and add/remove tiles.

Screenshots

iso hex

How Does This Work?

Quite simple there is a tile per entity. Behind the scenes the tiles are split into chunks that each have their own mesh which is sent to the GPU in an optimal way.

Why Use This Instead of X?

Because each tile is an entity of its own editing tiles is super easy and convenient. This allows you to tag entities for updating and makes stuff like animation easier. Want to have a mining simulation where damage is applied to tiles? That’s easy with this plugin:

struct Damage {
    amount: u32,
}

fn update_damage(
    mut query: Query<(&mut Tile, &Damage), Changed<Damage>>,
) {
    for (mut tile, damage) in query.iter_mut() {
        tile.texture_index = TILE_DAMAGE_OFFSET + damage.amount;
    }
}

Examples

  • accessing_tiles – An example showing how one can access tiles from the map object by using tile map coordinates.
  • animation – Basic CPU animation example.
  • atlas_spacing – Usage of atlas textures with multiple rows and spacing.
  • bench - A stress test of the map rendering system. Takes a while to load.
  • dynamic_map - A random map that is only partial filled with tiles that changes every so often.
  • game_of_life - A game of life simulator.
  • hex_column - A map that is meshed using “pointy” hexagons.
  • hex_row - A map that is meshed using flat hexagons.
  • iso_diamond - An isometric meshed map using diamond ordering.
  • iso_staggered - An isometric meshed map using staggered ordering.
  • layers - An example of how you can use multiple map entities/components for “layers”.
  • ldtk - An example of loading and rendering of a LDTK map which requires the ldtk feature. Use: cargo run --example ldtk --features ldtk
  • map - The simplest example of how to create a tile map.
  • random_map - A bench of editing all of the tiles every 100 ms.
  • remove_tiles - An example showing how you can remove tiles by using map_query
  • sparse_tiles - An example showing how to generate a map where not all of the tiles exist for a given square in the tile map.
  • tiled - An example of loading and rendering of a tiled map editor map which requires the tiled_map feature. Use: cargo run --example tiled --features tiled_map
  • tiled_rotate - An example of loading and rendering of a tiled map editor map with flipping and rotation.requires the tiled_map feature. Use: cargo run --example tiled_rotate --features tiled_map
  • visibility - An example showcasing visibility of tiles and chunks.

Running Examples

cargo run --release --example map

Running examples on web!

cargo build --target wasm32-unknown-unknown --example animation --release --features atlas
wasm-server-runner .\target\wasm32-unknown-unknown\release\examples\animation.wasm

Known Issues

  • Tile flipping by x, y and d, should work for all maps, however "d" (anti diagonal) flipping is not implemented for non-square maps.
  • Besides the above no known issues.

Asset credits

Dependencies

~21MB
~452K SLoC