#tilemap #grid #tile #render #screen #chunks

bevy_simple_tilemap

Refreshingly simple tilemap implementation for Bevy Engine

21 releases (breaking)

0.16.0 Nov 30, 2024
0.15.0 Jul 4, 2024
0.14.0 Feb 18, 2024
0.13.0 Nov 4, 2023
0.5.0 May 27, 2021

#138 in Game dev

Download history 32/week @ 2024-08-18 22/week @ 2024-08-25 30/week @ 2024-09-01 9/week @ 2024-09-08 12/week @ 2024-09-22 6/week @ 2024-09-29 2/week @ 2024-10-13 11/week @ 2024-11-03 100/week @ 2024-11-24 45/week @ 2024-12-01

145 downloads per month

MIT/Apache

48KB
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 image = asset_server.load("textures/tilesheet.png");
    let atlas = TextureAtlasLayout::from_grid(uvec2(16, 16), 4, 1, Some(uvec2(1, 1)), None);
    let atlas_handle = texture_atlases.add(atlas);

    // Spawn tilemap
    commands.spawn(TileMap::new(image, atlas_handle));
}

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

~42–75MB
~1.5M SLoC