bevy_tiles

Crates.iobevy_tiles
lib.rsbevy_tiles
version0.1.0
sourcesrc
created_at2024-03-05 22:54:26.451403
updated_at2024-04-20 19:43:44.020763
descriptionBevy library for working with entities in grids.
homepagehttps://github.com/OxidizedGames/bevy_tiles
repositoryhttps://github.com/OxidizedGames/bevy_tiles
max_upload_size
id1164146
size200,126
(jamescarterbell)

documentation

README

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
Commit count: 0

cargo fmt