#tilemap #bevy #tile #grid #chunks #render

bevy_simple_tilemap

Refreshingly simple tilemap implementation for Bevy Engine

19 releases (breaking)

0.14.0 Feb 18, 2024
0.13.0 Nov 4, 2023
0.12.0 Jul 9, 2023
0.11.0 Mar 6, 2023
0.5.0 May 27, 2021

#112 in Game dev

Download history 38/week @ 2023-12-04 14/week @ 2023-12-11 16/week @ 2023-12-18 13/week @ 2023-12-25 30/week @ 2024-01-01 14/week @ 2024-01-08 20/week @ 2024-01-15 14/week @ 2024-01-22 29/week @ 2024-01-29 14/week @ 2024-02-05 136/week @ 2024-02-12 139/week @ 2024-02-19 69/week @ 2024-02-26 24/week @ 2024-03-04 39/week @ 2024-03-11 26/week @ 2024-03-18

163 downloads per month
Used in bones_bevy_renderer

MIT/Apache

49KB
1K SLoC

bevy_simple_tilemap

CI GitHub release (latest by date) Crates.io

Refreshingly simple tilemap implementation for Bevy Engine.

Why another tilemap?

The main reason I started this was because I felt the existing tilemap implementations for Bevy were needlessly complicated to use when all you want to do is to as quickly and simply as possible render a grid of tiles to the screen, often exposing internal implementation details such as chunks to the user.

Goals:

  • Allow the user to render a grid of rectangular tiles to the screen
  • Make this as simple and intuitive as possible

Non-goals:

  • Supporting every imaginable shape of tile
  • 3D tilemaps
  • Assisting with non-rendering-related game-logic

How to use:

Spawning:

fn setup(
  asset_server: Res<AssetServer>,
  mut commands: Commands,
  mut texture_atlases: ResMut<Assets<TextureAtlas>>,
) {
    // Load tilesheet texture and make a texture atlas from it
    let texture = asset_server.load("textures/tilesheet.png");
    let atlas = TextureAtlasLayout::from_grid(vec2(16.0, 16.0), 4, 1, Some(vec2(1.0, 1.0)), None);
    let texture_atlas = texture_atlases.add(atlas);

    // Set up tilemap
    let tilemap_bundle = TileMapBundle {
        texture,
        atlas: TextureAtlas {
            layout: texture_atlas,
            ..Default::default()
        },
        ..Default::default()
    };

    // Spawn tilemap
    commands.spawn(tilemap_bundle);
}

Updating (or inserting) single tile:

tilemap.set_tile(ivec3(0, 0, 0), Some(Tile { sprite_index: 0, color: Color::WHITE }));

Updating (or inserting) multiple tiles:

// List to store set tile operations
let mut tiles: Vec<(IVec3, Option<Tile>)> = Vec::new();
tiles.push((ivec3(0, 0, 0), Some(Tile { sprite_index: 0, color: Color::WHITE })));
tiles.push((ivec3(1, 0, 0), Some(Tile { sprite_index: 1, color: Color::WHITE })));

// Perform tile update
tilemap.set_tiles(tiles);

Dependencies

~40–82MB
~1.5M SLoC