Crate bevy_ecs_tilemap
source · [−]Expand description
A tilemap rendering plugin for bevy which is more ECS friendly by having an entity per tile.
Features
- A tile per entity
- Fast rendering using a chunked approach.
- Layers and sparse tile maps.
- Animations
- Isometric and Hexagonal tile maps
Upcoming Features
Support for isometric and hexagon renderingdoneBuilt in animation support.done see animation example- Texture array support
Layers and add/remove tiles. (High Priority)done
Example
let texture_handle = asset_server.load("tiles.png");
let material_handle = materials.add(ColorMaterial::texture(texture_handle));
// Create map entity and component:
let map_entity = commands.spawn().id();
let mut map = Map::new(0u16, map_entity);
// Creates a new layer builder with a layer entity.
let (mut layer_builder, _) = LayerBuilder::new(
&mut commands,
LayerSettings::new(
MapSize(2, 2),
ChunkSize(8, 8),
TileSize(16.0, 16.0),
Vec2::new(96.0, 256.0),
),
0u16,
0u16,
);
layer_builder.set_all(TileBundle::default());
// Builds the layer.
// Note: Once this is called you can no longer edit the layer until a hard sync in bevy.
let layer_entity = map_query.build_layer(&mut commands, layer_builder, material_handle);
// Required to keep track of layers for a map internally.
map.add_layer(&mut commands, 0u16, layer_entity);
// Spawn Map
// Required in order to use map_query to retrieve layers/tiles.
commands.entity(map_entity)
.insert(map)
.insert(Transform::from_xyz(
-128.0,
-128.0,
0.0
))
.insert(GlobalTransform::default());
Modules
use bevy_ecs_tilemap::prelude::*; to import commonly used components, data structures, bundles, and plugins.
Structs
A component that stores information about a specific chunk in the tile map.
The position of a chunk within a map
The size of each chunk, in tiles
A component that is attached to a Tile entity that tells the GPU how to animate the tile. Currently all frames must be aligned in your tilemap.
A component which keeps information and a cache of tile/chunk entities for convenience.
Useful for creating and modifying a layer in the same system.
A bevy bundle which contains: Map, Transform, and GlobalTransform components.
Various settings used to define the tilemap.
The position of a tile, in chunk coordinates
A simple component used to keep track of layer entities.
MapQuery is a useful bevy system param that provides a standard API for interacting with tiles. It’s not required that you use this, but it does provide a convenience. Note: MapQuery doesn’t directly change tile components. This is meant as a feature as you may have your own tile data attached to each tile and a standard tile query wouldn’t pull that data in.
The size of the map, in chunks
The size of a texture in pixels
A component that represents the basic tile information.
Used to build a TextureAtlas
that maintains the order of the textures added.
The standard tile bundle.
A component containing the tiles parent information.
The position of a tile, in map coordinates
The size of each tile, in pixels
Adds the default systems and pipelines used by bevy_ecs_tilemap.
The tilemap stage which runs before post update.
Enums
Different hex coordinate systems. You can find out more at this link: https://www.redblobgames.com/grids/hexagons/
Different iso coordinate systems.
General errors that are returned by bevy_ecs_tilemap.
The tilemap system labels
The type of tile to be rendered, currently we support: Square, Hex, and Isometric.
Traits
This trait is used to allow the layer builder to access specific information inside of the bundle.