From v0.3.X to v0.4.X
Overview
Version 0.4 was initially motivated by an update to the way we handle user properties but ended as a major overhaul of the plugin to provide a better API and to give more control to the user.
Plugin instanciation
The plugin now has an associated configuration, which you need to provide when you add it to your application.
The easiest way is to use the default configuration value :
use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; fn main() { App::new() // You still need the bevy_ecs_tilemap plugin .add_plugins(TilemapPlugin) // And now, you have to provide a configuration for bevy_ecs_tiled plugin .add_plugins(TiledMapPlugin::default()) .run(); }
The plugin configuration is described in the API reference
Tiled map spawn and configuration
The plugin entry point, ie. the TiledMapBundle
bundle is gone.
It was cumbersome and did not allow for a proper separation of concerns (for instance, for physics).
Also, the Handle<TiledMap>
type is not a Bevy component anymore.
It was done in order to anticipate expected changes in Bevy where Handle<T>
won't be able to derive the Component
trait anymore.
Anyway, the new way to spawn a map is now easier: you just have to spawn a TiledMapHandle
referencing your .TMX file asset:
#![allow(unused)] fn main() { use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; fn startup(mut commands: Commands, asset_server: Res<AssetServer>) { // 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)); } }
You can customize various settings about how to load the map by inserting the TiledMapSettings
component on the map entity.
Tiled user properties
Before this change, you had to define your custom types both in Tiled and in your rust code. It was not user-friendly and error-prone.
Now, we take advantage of bevy_reflect
to generate a file containing all the types known to Bevy.
This file can be imported in Tiled so you can use these types directly in the editor.
Migrating from the old implementation should be straight-forward.
First, you need need to update your custom types so they actually implement the Reflect
trait :
- remove
#[derive(TiledObject)]
,#[derive(TiledCustomTile)]
,#[derive(TiledClass)]
and#[derive(TiledEnum)]
derived traits. Make sure to also remove associated attributes. - add
#[derive(Reflect)]
derive trait on the types you want to use in Tiled. - make sure your components have the
#[reflect(Component)]
attribute
Then, in your main / in your plugin setup, you then need to register your types with Bevy :
- replace calls to
register_tiled_object::<T>()
with calls toregister_type::<T>()
. - replace calls to
register_tiled_custom_tile::<T>()
with calls toregister_type::<T>()
.
The final step is to actually generate the types import file (run your game once) and import the types to Tiled. Note that you may have to update your map / your tilesets to use the new types you just imported.
A dedicated guide about how to setup user properties is available in this book.
Tiled physics
Eventhough functionnalities around physics did not change much, the internals have been completely reworked and the API was updated a bit.
Notably, now you need to instanciate another plugin and specify which physics backend you want to use. The physics section of the book should get you through.
Map events
This is a new feature of this version which gives more control to the user over what he wants to do with a Tiled map. More information in the dedicated section
Misc changes
enum MapPositioning
Both enum name and fields name have been updated to better reflect what they actually do.
You should now use the new LayerPositioning
enum.
fn from_isometric_coords_to_bevy()
Parameters tiled_position: Vec2
and iso_coords: IsoCoordSystem
have been swapped for better consistency with other utility functions.