#bevy-ecs #tilemap #tile #rendering #animation #hexagonal #entity

bevy_ecs_tilemap

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

12 breaking releases

0.14.0 Jul 18, 2024
0.12.0 Feb 11, 2024
0.11.1 Oct 15, 2023
0.11.0 Jul 23, 2023
0.4.0 May 27, 2021

#16 in Game dev

Download history 593/week @ 2024-08-05 989/week @ 2024-08-12 571/week @ 2024-08-19 571/week @ 2024-08-26 719/week @ 2024-09-02 617/week @ 2024-09-09 641/week @ 2024-09-16 795/week @ 2024-09-23 748/week @ 2024-09-30 192/week @ 2024-10-07 750/week @ 2024-10-14 557/week @ 2024-10-21 768/week @ 2024-10-28 662/week @ 2024-11-04 292/week @ 2024-11-11 450/week @ 2024-11-18

2,247 downloads per month
Used in 6 crates (5 directly)

MIT license

265KB
6K 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.
  • Examples for integration with Tiled and LDTK editors.

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 TileTexture, &Damage), Changed<Damage>>,
) {
    for (mut tile_texture, damage) in query.iter_mut() {
        tile_texture.0 = 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.
  • basic - The simplest example of how to create a tile map.
  • bench - A stress test of the map rendering system. Takes a while to load.
  • chunking - A simple example showing how to implement an infinite tilemap by spawning multiple chunks.
  • colors - Showcases how each tile can have an individual color.
  • frustum_cull_test - An environment for testing frustum culling.
  • game_of_life - A game of life simulator.
  • hexagon_column - A map that is meshed using “pointy” hexagons.
  • hexagon_generation - Shows how to generate hexagonal maps.
  • hexagon_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. We recommend checking out bevy_ecs_ldtk(https://crates.io/crates/bevy_ecs_ldtk).
  • mouse_to_tile - Shows how to convert a mouse cursor position into a tile position.
  • move_tile - Shows how to move a tile without despawning and respawning it.
  • 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
  • spacing - Shows how to load tilemap textures that contain spacing between the tiles.
  • tiled - An example of loading and rendering of a Tiled editor map.
  • tiled_rotated - An example of loading and rendering of a Tiled editor map with flipping and rotation.
  • visibility - An example showcasing visibility of tiles and chunks.

Running Examples

cargo run --release --example basic

Running examples on web

This can be made simple with wasm-server-runner.

After that's installed and configured, run:

WebGL2

cargo run --target wasm32-unknown-unknown --example animation --release --features atlas,bevy/webgl2

Note: You must use the atlas feature when targeting the web with WebGL2. See #283.

WebGPU

WebGPU is not yet well supported by many browsers.

RUSTFLAGS=--cfg=web_sys_unstable_apis cargo run --example animation --target=wasm32-unknown-unknown

Bevy Compatibility

bevy bevy_ecs_tilemap
main bevy-track
0.12 0.12
0.11 0.11.*
0.10 0.10
0.9 0.9
0.8 0.8
0.8 0.7
0.7 0.6
0.6 0.5

Asset credits

Dependencies

~39–76MB
~1.5M SLoC