StarArawn / bevy_ecs_tilemap

A tilemap rendering crate for bevy which is more ECS friendly.
MIT License
853 stars 189 forks source link

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

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

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