Crate bevy_ecs_tiled

Source
Expand description

bevy_ecs_tiled is a Bevy plugin for working with 2D tilemaps created with the Tiled map editor.

It relies upon:

Each tile or object is represented by a Bevy entity:

  • layers are children of the tilemap entity
  • tiles and objects are children of layers

Visibility and Transform are inherited: map -> layer -> tile / object

§API reference

As the name implies, this API reference purpose is to describe the API provided by bevy_ecs_tiled.

For a more use-cases oriented documentation please have a look to the bevy_ecs_tiled book and notably the FAQ that will hopefully answer most of your questions.

§Getting started

Add dependencies to your Cargo.toml file:

[dependencies]
bevy = "0.14"
bevy_ecs_tiled = "0.4"
bevy_ecs_tilemap = "0.14"

Then add the plugin to your app and spawn a map:

use bevy::prelude::*;
use bevy_ecs_tiled::prelude::*;
use bevy_ecs_tilemap::prelude::*;

fn main() {
    App::new()
        // Add Bevy default plugins
        .add_plugins(DefaultPlugins)
        // Add bevy_ecs_tilemap plugin
        .add_plugins(TilemapPlugin)
        // Add bevy_ecs_tiled plugin
        .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 2D camera
    commands.spawn(Camera2dBundle::default());

    // Load the map: ensure any tile / tileset paths are relative to assets/ folder
    let map_handle: Handle<TiledMap> = asset_server.load("map.tmx");

    // Spawn the map with default options
    commands.spawn(TiledMapHandle(map_handle));
}

Please note that you should have the map.tmx file in your local assets/ folder, as well as required dependencies (for instance, associated tilesets).

You can customize various settings about how to load the map by inserting the TiledMapSettings component on the map entity.

Also, you can browse the examples for more advanced use cases.

Modules§

  • This module contains all Assets definition.
  • This module contains all Components definition.
  • This module contains some tools to help you debug your application.
  • Events related to Tiled map loading
  • This module handles the actual Tiled map loading.
  • This module contains utilities to work with Tiled names.
  • This module handles all things related to physics.
  • bevy_ecs_tiled public exports.
  • This module handles all things related to Tiled custom properties.
  • This module contains utilities functions.

Structs§