#tilemap #tile #chunk #grid #bevy #entity #entities

bevy_tiles

Bevy library for working with entities in grids

3 unstable releases

0.1.0 Apr 20, 2024
0.0.0-dev2 Apr 15, 2024
0.0.0-dev1 Mar 5, 2024

#1066 in Game dev

Custom license

83KB
1.5K SLoC

bevy_tiles

Crates.io docs license Crates.io

A general purpose grided entity library meant to support tilemap libraries, or other libraries that require accessing entities in a grid based manner. The goal is to keep the API surface as simple and intuitive as possible, and to avoid deferred operations/states where possible to make the structures more intuitive work with (ex: an update in one system should be seen by the following system, not the following frame when a system has run.).

Features

Currently, bevy_tiles supports the following:

  • Automatic chunking (including access to chunk entities)
  • Automatic map creation
  • Hierarchical despawning of chunks and maps
  • N-dimensional map support
  • Map based quiries
  • Spatial queries
  • Batched operations for better performance on large groups of tiles or chunks

Upcoming features:

  • Automagically handle hierarchical deletes.
  • Sort tiles in memory based on chunk and map (will require bevy API additions in the future).

API

The basic API revolves around TileQuery's, TileCommands, and TileMapLabel's as seen below.

struct GameLayer;

impl TileMapLabel for GameLayer {
    const CHUNK_SIZE: usize = 16;
}

fn move_character(
    keyboard_input: Res<Input<KeyCode>>,
    mut commands: Commands,
    character: TileQuery<GameLayer, TileCoord, With<Character>>,
    walls: TileQuery<GameLayer, (), With<Block>>,
) {
    let mut tile_commands = commands.tiles::<GameLayer, 2>();

    let mut x = if keyboard_input.just_pressed(KeyCode::A) {
        -1
    } else {
        0
    };

    x += if keyboard_input.just_pressed(KeyCode::D) {
        1
    } else {
        0
    };

    let char_c = character.single();
    let new_coord = [char_c[0] + x, char_c[1] + y];

    if walls.get_at(new_coord).is_none() {
        tile_commands.move_tile(*char_c, new_coord);
    }
}

More examples can be found in the examples folder!

Versions

Bevy version bevy_tiles verison
0.13 0.2
0.12 0.1
0.11 0.1-dev

Dependencies

~20–47MB
~770K SLoC