Crates.io | bevy_ecs_tiled |
lib.rs | bevy_ecs_tiled |
version | 0.6.0 |
source | src |
created_at | 2024-07-13 10:34:03.768696+00 |
updated_at | 2025-03-15 17:21:00.952198+00 |
description | A Bevy plugin for loading Tiled maps |
homepage | https://github.com/adrien-bon/bevy_ecs_tiled |
repository | https://github.com/adrien-bon/bevy_ecs_tiled |
max_upload_size | |
id | 1302227 |
size | 732,708 |
bevy_ecs_tiled
is a Bevy plugin for working with 2D tilemaps created with the Tiled map editor.
It relies upon the official Tiled Rust bindings to parse and load Tiled map files and the bevy_ecs_tilemap
crate to perform rendering.
It aims to provide a simple and ergonomic workflow by using Tiled as an editor when working on Bevy 2D games.
Visibility
and Transform
are automatically propagated down the hierarchy.Update your Bevy components directly from Tiled editor :
Use several maps to build a huge world :
This crate is documented in three places:
bevy_ecs_tiled
book with design explanations, how-to guides and migrations guides.There is notably a FAQ that will hopefully answer most of your questions.
Good reading!
Add required dependencies to your Cargo.toml
file:
[dependencies]
bevy = "0.15"
bevy_ecs_tiled = "0.6"
bevy_ecs_tilemap = "0.15"
Then add the plugin to your app and spawn a map.
Basically, all you have to do is to spawn a TiledMapHandle
with the map asset you want to load (the map.tmx
file).
Note that this map asset should be in your local assets folder, as well as required dependencies (such as images or tilesets).
By default, this is the ./assets/
folder.
use bevy::prelude::*;
use bevy_ecs_tiled::prelude::*;
fn main() {
App::new()
// Add Bevy default plugins
.add_plugins(DefaultPlugins)
// Add bevy_ecs_tiled plugin: note that bevy_ecs_tilemap::TilemapPlugin
// will be automatically added as well if it's not already done
.add_plugins(TiledMapPlugin::default())
// Add our startup function to the schedule and run the app
.add_systems(Startup, startup)
.run();
}
fn startup(
mut commands: Commands,
asset_server: Res<AssetServer>
) {
// Spawn a Bevy 2D camera
commands.spawn(Camera2d);
// Load a map asset and retrieve the corresponding handle
let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");
// Spawn a new entity with this handle
commands.spawn(TiledMapHandle(map_handle));
}
This simplistic example will load a map using default settings. You can tweak how to load the map by adding various components on the map entity, notably:
For instance, here's how you load a map but change its anchor point to be at center instead of bottom-left :
use bevy::prelude::*;
use bevy_ecs_tiled::prelude::*;
fn spawn_map(
mut commands: Commands,
asset_server: Res<AssetServer>
) {
// You can also spawn your map and associated settings as a single bundle
commands.spawn((
TiledMapHandle(asset_server.load("map.tmx")),
TiledMapAnchor::Center,
));
}
You can browse the examples for more advanced use cases.
bevy | bevy_ecs_tilemap | bevy_ecs_tiled |
---|---|---|
0.15 | 0.15 | 0.5 - 0.6 |
0.14 | 0.14 | 0.3 - 0.4 |
0.13 | main@e4f3cc6 | branch 0.2 |
0.12 | 0.12 | 0.1 |
If you can contribute, please do!
If you would like to contribute but don't know where to start, read this section in the book.
This work is licensed under the MIT license.
SPDX-License-Identifier: MIT