### Run an Example Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/examples/README.md To run an example, use the cargo run command with the --example flag followed by the example name. Some examples may require specific feature flags. ```bash cargo run --example XXX ``` -------------------------------- ### Run Demo Platformer Example Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/examples/demo_platformer/README.md Command to run the demo_platformer example. Ensure to enable the 'avian' and 'user_properties' features. ```bash cargo run --example demo_platformer --features="avian user_properties" ``` -------------------------------- ### Basic Bevy App Setup with TiledPlugin Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/getting-started.md Configure a Bevy application to use the TiledPlugin and spawn a map entity. Ensure your map asset is in the local assets folder. ```rust use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; fn main() { App::new() // Add Bevy's default plugins .add_plugins(DefaultPlugins) // Add the bevy_ecs_tiled plugin // bevy_ecs_tilemap::TilemapPlugin will be added automatically if needed .add_plugins(TiledPlugin::default()) // Add your startup system and run the app .add_systems(Startup, startup) .run(); } fn startup( mut commands: Commands, asset_server: Res, ) { // Spawn a 2D camera commands.spawn(Camera2d); // Load a map asset and retrieve its handle let map_handle: Handle = asset_server.load("map.tmx"); // Spawn a new entity with the TiledMap component commands.spawn(TiledMap(map_handle)); } ``` -------------------------------- ### Instantiating TiledMapPlugin (After v0.6) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_6.md From version 0.6 onwards, `TiledMapPlugin` automatically instantiates `TilemapPlugin` if it hasn't been added already, simplifying plugin setup. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn main() { App::new() // Main plugin from bevy_ecs_tiled: // implicitely load bevy_ecs_tilemap main plugin .add_plugins(TiledMapPlugin::default()); } ``` -------------------------------- ### Spawn Tiled Map with Center Anchor (Before v0.7) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_7.md Example of spawning a tiled map with the deprecated TiledMapAnchor::Center before version 0.7. ```rust commands.spawn(( TiledMapHandle(asset_server.load("map.tmx")), TiledMapAnchor::Center, )); ``` -------------------------------- ### Spawn Tiled Map with Center Anchor (After v0.7) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_7.md Example of spawning a tiled map with the new TilemapAnchor::Center after version 0.7, utilizing the updated component from bevy_ecs_tilemap. ```rust commands.spawn(( TiledMapHandle(asset_server.load("map.tmx")), TilemapAnchor::Center, )); ``` -------------------------------- ### Add Static RigidBody to Tiled Object Colliders Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/physics.md Listen for ColliderCreated events and add a RigidBody::Static component to entities originating from Tiled objects. This example uses the Avian physics backend. ```rust use bevy::prelude::* use avian2d::prelude::* use bevy_ecs_tiled::prelude::* fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2d); commands .spawn(TiledMap(asset_server.load("map.tmx"))) .observe(|collider_created: On>, mut commands: Commands| { // Filter collider created from Tiled objects if collider_created.event().event.source == TiledCollider::Object { // Add a RigidBody::Static to the collider entity commands .entity(collider_created.event().origin) .insert(RigidBody::Static); } }); } ``` -------------------------------- ### Filter Colliders by Object/Layer Name with Avian Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/physics.md Configure TiledPhysicsSettings to spawn colliders only for objects or tile layers matching specific names. This example uses the Avian backend. ```rust use bevy::prelude::*; use avian2d::prelude::*; use bevy_ecs_tiled::prelude::*; fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2d); commands.spawn(( TiledMap(asset_server.load("finite.tmx")), // Restrict colliders to: // - objects named 'hitbox' or 'collision' // - tile colliders in a layer named 'collision' TiledPhysicsSettings:: { objects_filter: TiledFilter::Names(vec!["hitbox".into(), "collision".into()]), tiles_layer_filter: TiledFilter::Names(vec!["collision".into()]), ..default() }, )); } ``` -------------------------------- ### Update TiledAnimation Struct (v0.11 vs v0.12) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_12.md The TiledAnimation API has been redesigned. In v0.11, it used start, end, and frame_duration. In v0.12, it uses a 'frames' vector of (atlas_index, duration_in_seconds) tuples and a 'current_frame' field. ```rust pub struct TiledAnimation { pub start: usize, pub end: usize, pub frame_duration: f32, } ``` ```rust pub struct TiledAnimation { pub frames: Vec<(usize, f32)>, // (atlas_index, duration_in_seconds) pub current_frame: usize, } ``` -------------------------------- ### Initialize Bevy App with Avian Physics Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/physics.md Set up your Bevy application by adding the TiledPlugin, TiledPhysicsPlugin with the Avian backend, and Avian's PhysicsPlugins. Ensure the length unit is configured. ```rust use bevy::prelude::*; use avian2d::prelude::*; use bevy_ecs_tiled::prelude::*; // You must enable the 'avian' feature for bevy_ecs_tiled fn main() { App::new() // Load bevy_ecs_tiled main plugin .add_plugins(TiledPlugin::default()) // Load bevy_ecs_tiled physics plugin (select Avian backend) .add_plugins(TiledPhysicsPlugin::::default()) // Load Avian main plugin .add_plugins(PhysicsPlugins::default().with_length_unit(100.0)) // Add your systems and run the app! .add_systems(Startup, startup) .run(); } fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2d); commands.spawn(TiledMap(asset_server.load("map.tmx"))); } ``` -------------------------------- ### Instantiating TilemapPlugin (Before v0.6) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_6.md In versions prior to 0.6, both `TilemapPlugin` and `TiledMapPlugin` needed to be manually added to the Bevy application. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* use bevy_ecs_tilemap::prelude::* fn main() { App::new() // Main plugin from bevy_ecs_tilemap .add_plugins(TilemapPlugin) // Main plugin from bevy_ecs_tiled .add_plugins(TiledMapPlugin::default()); } ``` -------------------------------- ### Basic Map Anchor Usage Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/examples/README.md Demonstrates the basic usage of TilemapAnchor. ```rust # Examples This directory provides a collection of examples demonstrating how to use the `bevy_ecs_tiled` crate in various scenarios. To run an example, use the following command, replacing `XXX` with the example name: ```bash cargo run --example XXX ``` > **Note:** > Some examples require one or more feature flags to be enabled. > If you attempt to run such an example without the required features, Cargo will display an error message with the correct command to use. For a more in-depth explanation of crate concepts, see the [dedicated book](https://adrien-bon.github.io/bevy_ecs_tiled/) or the [demo_platformer](./demo_platformer/) example.. ## Keyboard Controls Most examples support the following controls: - **WASD**: Move the camera - **Z/X**: Zoom out / zoom in - **A/E**: Rotate the map (not just the camera) > **Note for non-QWERTY layouts:** > Some keys may differ. > For example, on an AZERTY keyboard, use `A` instead of `Q` and `Z` instead of `W`. ## Examples List | Name | Required features | Description | |------|-------------------|-------------| | `map_anchor` | `debug` | This example shows the basic usage of `TilemapAnchor`. | | `map_basic` | None | This example shows the basic usage of the plugin to load a Tiled map. | | `map_events` | None | This example shows how to use map loading events. | | `map_parallax` | None | This example demonstrates parallax scrolling with Tiled map layers. | | `map_reload` | None | This example demonstrates how to load and unload maps. | | `map_settings` | None | This example cycles through different map settings that can be applied. | | `map_spawn_delay` | None | This example will delay map spawn from asset loading to demonstrate both are decoupled. | | `map_text` | text | This example demonstrates loading a map with a Tiled text. | | `orientation_hexagonal` | `debug` | This example cycles through different kinds of hexagonal maps. | | `orientation_isometric` | `debug` | This example cycles through different kinds of isometric maps. | | `orientation_orthogonal` | `debug` | This example cycles through different kinds of orthogonal maps. | | `physics_avian_controller` | `avian_debug` | This example shows a simple player-controlled object using Avian2D physics. You can move the object using arrow keys. | | `physics_avian_orientation` | `avian_debug` | This example shows Avian2D physics backend with various map orientation. | | `physics_avian_settings` | `avian_debug` | This example shows how to use Avian2D physics backend. | | `physics_custom` | `physics` | This example shows how to use a custom physics backend. | | `physics_rapier_controller` | `rapier_debug` | This example shows a simple player-controlled object using Rapier physics. You can move the object using arrow keys. | | `physics_rapier_orientation` | `rapier_debug` | This example shows Rapier physics backend with various map orientation. | | `physics_rapier_settings` | `rapier_debug` | This example shows how to use Rapier physics backend. | | `properties_basic` | `user_properties` | This example shows how to map custom tiles and objects properties from Tiled to Bevy Components. | | `world_basic` | None | This example shows the basic usage of the plugin to load a Tiled world. | | `world_chunking` | `debug` | This example shows how to load Tiled World files and demonstrates chunking the loaded maps. | ``` -------------------------------- ### Import Specific Type from Prelude Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_8.md Alternatively, import specific types like `TiledPlugin` from the prelude. ```rust use bevy_ecs_tiled::prelude::TiledPlugin; ``` -------------------------------- ### Add Default TiledMapPlugin Configuration Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_4.md Instantiate the TiledMapPlugin with its default configuration when adding it to your Bevy application. ```rust 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(); } ``` -------------------------------- ### Import Prelude for Type Adjustments Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_8.md To simplify type adjustments after renaming, import the entire prelude. ```rust use bevy_ecs_tiled::prelude::*; ``` -------------------------------- ### Observe TiledEvent with Observers Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/design/map_events.md Demonstrates spawning a map and attaching an observer to detect TiledEvent for inline logic. Requires Bevy and Bevy ECS Tiled prelude imports. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn startup(mut commands: Commands, asset_server: Res) { commands // Spawn a map and attach an observer on it. .spawn(TiledMap( asset_server.load("maps/orthogonal/finite.tmx"), )) // Add an "in-line" observer to detect when the map has finished loading .observe(|_: On>, map_query: Query<&Name, With>| { if let Some(map_entity) = e.get_map_entity() { if let Ok(name) = map_query.get(map_entity) { info!("=> Observer TiledMapCreated was triggered for map '{}'", name); } } }); } ``` -------------------------------- ### Spawn a Tiled Map Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/spawn_reload.md Loads a Tiled map asset and spawns it as a Bevy entity. This is the initial step to display a map in your game. ```rust fn spawn_map( mut commands: Commands, asset_server: Res ) { // Load the map asset let map_handle: Handle = asset_server.load("map.tmx"); // Spawn the map entity with default settings commands.spawn(TiledMap(map_handle)); } ``` -------------------------------- ### Add Dependencies to Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/getting-started.md Include the necessary Bevy and Bevy ECS Tiled crates in your project's dependencies. ```toml [dependencies] bevy = "0.18" bevy_ecs_tiled = "0.11" ``` -------------------------------- ### Update TiledMapSettings: Before Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_5.md Shows the previous method of setting map transform and visibility using `TiledMapSettings` before version 0.5.X. ```rust let map_handle: Handle = asset_server.load("map.tmx"); commands.spawn(( TiledMapHandle(map_handle), TiledMapSettings { map_initial_transform: Transform::from_xyz(150., 100., 0.), map_initial_visibility: Visibility::Hidden, ..Default::default() }, )); ``` -------------------------------- ### Handle TiledEvent with Buffered Events Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/design/map_events.md Shows how to use MessageReader to listen for TiledEvent and query for the map's name. Requires Bevy and Bevy ECS Tiled prelude imports. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn handle_map_event( mut map_events: MessageReader>, map_query: Query<&Name, With>, ) { for e in map_events.read() { if let Some(map_entity) = e.get_map_entity() { if let Ok(name) = map_query.get(map_entity) { info!("=> Received TiledMapCreated event for map '{}'", name); } } } } ``` -------------------------------- ### Add bevy-inspector-egui WorldInspectorPlugin Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Integrate the WorldInspectorPlugin from bevy-inspector-egui to enable real-time browsing and editing of game world components. ```rust use bevy::prelude::* use bevy_inspector_egui::quick::WorldInspectorPlugin; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(EguiPlugin { enable_multipass_for_primary_context: true }) .add_plugins(WorldInspectorPlugin::new()) .run(); } ``` -------------------------------- ### Handle TiledEvent Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/design/map_events.md Demonstrates how to read TiledEvent and access map asset information using get_map_asset(). Requires MessageReader and TiledEvent imports. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn handle_event( mut object_events: MessageReader>, ) { // Even though we receive an event for a Tiled object, // we can retrieve information about the Tiled map for e in object_events.read() { let object_entity = e.origin; if let Some(map_asset) = e.get_map_asset() { info!("Received TiledEvent for: '{:?}'", map_asset); } } } ``` -------------------------------- ### Add Rapier Physics Debug Render Plugin Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Integrate the RapierDebugRenderPlugin for visualizing physics bodies and colliders when using Rapier with Bevy. ```rust use bevy::prelude::* use bevy_rapier2d::prelude::* fn main() { App::new() // Add Rapier regular plugin .add_plugins(RapierPhysicsPlugin::::pixels_per_meter(100.0)) // Add Rapier debug plugin .add_plugins(RapierDebugRenderPlugin::default()) .run(); } ``` -------------------------------- ### Spawn Tiled Map using TiledMapHandle Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_4.md Spawn a Tiled map by creating a TiledMapHandle component that references the .TMX file asset. This replaces the previous TiledMapBundle. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn startup(mut commands: Commands, asset_server: Res) { // Load the map: ensure any tile / tileset paths are relative to assets/ folder let map_handle: Handle = asset_server.load("map.tmx"); // Spawn the map with default options commands.spawn(TiledMapHandle(map_handle)); } ``` -------------------------------- ### Add bevy_ecs_tiled Dependency Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/README.md Add the bevy_ecs_tiled crate to your Cargo.toml file to include it in your project. Ensure you also have the correct Bevy version specified. ```toml [dependencies] bevy = "0.18" bevy_ecs_tiled = "0.11" ``` -------------------------------- ### Reacting to Custom Properties with Bevy Observers Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/properties.md Use Bevy's `On` observers to react when a Tiled object with a specific marker component is spawned. This allows you to insert additional components or spawn other entities based on custom properties. ```rust use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; // Declare a marker component: assume it will be added to a particular Tiled object #[derive(Component, Default, Debug, Reflect)] #[reflect(Component, Default)] struct PlayerSpawn; fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2d); commands .spawn(TiledMap(asset_server.load("map.tmx"))) // We will run this observer for every Tiled object with the `PlayerSpawn` component .observe(|add_player_spawn: On, mut commands: Commands| { // Retrieve the Tiled object entity let player_spawn_entity = add_player_spawn.event().entity; // Add extra components commands .entity(player_spawn_entity) .insert(( ... )); }); } ``` -------------------------------- ### Update TiledMapSettings: After Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_5.md Illustrates the new method of setting map transform and visibility by directly inserting `Transform` and `Visibility` components on the map entity after version 0.5.X. ```rust let map_handle: Handle = asset_server.load("map.tmx"); commands.spawn(( TiledMapHandle(map_handle), Transform::from_xyz(150., 100., 0.), Visibility::Hidden, )); ``` -------------------------------- ### Add Avian Physics Backend Dependency Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/physics.md Add the 'avian' feature to your bevy_ecs_tiled dependency in Cargo.toml to enable Avian physics integration. ```toml [dependencies] bevy = "0.16" bevy_ecs_tiled = { version = "0.10", features = ["avian"] } ``` -------------------------------- ### Add TiledDebugPluginGroup Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Enable all provided bevy_ecs_tiled debug plugins at once by adding TiledDebugPluginGroup to your Bevy app. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn main() { App::new() .add_plugins(TiledDebugPluginGroup) .run(); } ``` -------------------------------- ### Map Loading Events (Before v0.6) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_6.md Previously, map loading events used a single global observer and a method that could panic if map data retrieval failed. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn main() { App::new() .add_plugins(TiledMapPlugin::default()) .add_systems(Startup, startup) // Previously, we could only use a global observer .add_observer(|trigger: Trigger, map_asset: Res>| { // Previously, the method to retrieve map data would panic in case of error let map = trigger.event().map(&map_asset); info!( ``` ```rust fn startup( mut commands: Commands, asset_server: Res ) { commands.spawn(TiledMapHandle(asset_server.load("map.tmx"))); } ``` -------------------------------- ### Add Avian Physics Debug Plugin Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Include the PhysicsDebugPlugin from Avian to visualize physics colliders and interactions within your Bevy application. ```rust use bevy::prelude::* use avian2d::prelude::* fn main() { App::new() // Add Avian regular plugin .add_plugins(PhysicsPlugins::default().with_length_unit(100.0)) // Add Avian debug plugin .add_plugins(PhysicsDebugPlugin::default()) .run(); } ``` -------------------------------- ### Update Dependency in Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_8.md Update the `bevy_ecs_tiled` dependency to version 0.8 in your `Cargo.toml` file. ```toml bevy_ecs_tiled = "0.8" ``` -------------------------------- ### Set RUST_LOG to trace Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Set the RUST_LOG environment variable to 'trace' to display all logs at the trace level. This can be very verbose. ```sh RUST_LOG=trace cargo run ``` -------------------------------- ### Spawn Tiled World Component Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/FAQ.md Use the TiledWorld component to spawn a Tiled world by loading a .world asset. This is useful for managing large game maps composed of multiple Tiled maps. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn startup( mut commands: Commands, asset_server: Res, ) { // Spawn a new entity with the TiledWorld component commands.spawn( TiledWorld(asset_server.load("demo.world")) ); } ``` -------------------------------- ### Customizing Map Loading with Components and Observers Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/getting-started.md Spawn a map with a custom anchor point and observe the TiledEvent to access map data and spawned entities. This allows for dynamic map loading and processing. ```rust use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; fn spawn_map( mut commands: Commands, asset_server: Res, ) { commands // Load a map and set its anchor point to the // center instead of the default bottom-left .spawn( (TiledMap(asset_server.load("map.tmx")), TilemapAnchor::Center, ) ) // Add an "in-line" observer to detect when // the map has finished loading .observe( |map_created: On>, assets: Res>, query: Query<(&Name, &TiledMapStorage), With>| { // We can access the map components via a regular query let Ok((name, storage)) = query.get(map_created.event().origin) else { return; }; info!("=> Observer TiledMapCreated was triggered for map '{name}'"); // Or directly the underneath raw tiled::Map data let Some(map) = map_created.event().get_map(&assets) else { return; }; info!("Loaded map: {:?}", map); // Additionally, we can access Tiled items using the TiledMapStorage // component: we can retrieve Tiled items entity and access // their own components with another query (not shown here). // This can be useful if you want for instance to create a resource // based upon tiles or objects data but make it available only when // the map is actually spawned. for (id, entity) in storage.objects() { info!( "(map) Object ID {:?} was spawned as entity {:?}", id, entity ); } } ); } ``` -------------------------------- ### Update Dependencies for Bevy v0.18 and bevy_ecs_tiled v0.11 Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_11.md Update your Cargo.toml file to specify the required versions for Bevy and bevy_ecs_tiled. Ensure other Bevy-related crates are also compatible. ```toml bevy = "0.18" bevy_ecs_tiled = "0.11" ``` -------------------------------- ### Enable User Properties Feature in Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/properties.md To use custom properties, update your Cargo.toml file to include the `user_properties` feature for the `bevy_ecs_tiled` dependency. Adjust versions as necessary. ```toml [dependencies] bevy = "0.16" bevy_ecs_tiled = { version = "0.10", features = ["user_properties"] } ``` -------------------------------- ### Map Loading Events (After v0.6 - Entity-Scoped Observer) Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_6.md In v0.6, entity-scoped observers are available for map loading events. The `get_map` method now returns an `Option` to prevent panics. ```rust use bevy::prelude::* use bevy_ecs_tiled::prelude::* fn main() { App::new() .add_plugins(TiledMapPlugin::default()) .add_systems(Startup, startup) .add_systems(Update, read_map_events); } fn startup(mut commands: Commands, asset_server: Res) { commands .spawn(TiledMapHandle(asset_server.load("map.tmx"))) // Now, you can use an entity-scoped observer .observe( |trigger: Trigger, map_asset: Res>| { // Now, this method return an Option and don't panic in case of error if let Some(map) = trigger.event().get_map(&map_asset) { info!("(observer) Loaded map: {:?}", map); } }, ); } // Or a regular event fn read_map_events(mut map_events: EventReader, map_asset: Res>) { for event in map_events.read() { if let Some(map) = event.get_map(&map_asset) { info!("(event) Loaded map: {:?}", map); } } } ``` -------------------------------- ### Update Dependencies in Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_12.md Update your Cargo.toml file to specify version 0.12 for bevy_ecs_tiled and compatible versions for physics backends like avian2d or bevy_rapier2d. ```toml bevy = "0.18" bevy_ecs_tiled = "0.12" avian2d = "0.6" # if using Avian physics bevy_rapier2d = "0.34" # if using Rapier physics ``` -------------------------------- ### Filter logs for bevy_ecs_tiled Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/debug.md Filter logs to only display information from the 'bevy_ecs_tiled' crate at the trace level by setting RUST_LOG. ```sh RUST_LOG=bevy_ecs_tiled=trace cargo run ``` -------------------------------- ### Update Dependencies in Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_10.md Update your Cargo.toml file to specify Bevy v0.17 and bevy_ecs_tiled v0.10. Ensure compatibility with other Bevy-related crates. ```toml bevy = "0.17" bevy_ecs_tiled = "0.10" ``` -------------------------------- ### Update Dependency in Cargo.toml Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_9.md Update the bevy_ecs_tiled dependency to version 0.9 in your Cargo.toml file. ```toml bevy_ecs_tiled = "0.9" ``` -------------------------------- ### Load a New Map Over an Existing One Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/spawn_reload.md Replaces the current Tiled map with a new one by inserting a new TiledMap component onto the existing map entity. If the same map handle is used, it acts like RespawnTiledMap. ```rust fn handle_reload( mut commands: Commands, asset_server: Res, map_query: Query>, ) { if let Ok(entity) = map_query.single() { commands.entity(entity) .insert( TiledMap(asset_server.load("other_map.tmx")) ); } } ``` -------------------------------- ### Declare and Register Reflectable Custom Types in Rust Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/properties.md Define your custom data structures in Rust, deriving `Reflect` and `Default` to make them compatible with Tiled custom properties. Register the top-level struct with Bevy's type registry. ```rust use bevy::prelude::*; // Declare a component and make it reflectable #[derive(Component, Reflect, Default)] #[reflect(Component, Default)] struct Biome { block_line_of_sight: bool, ty: BiomeType, } // Any sub-type must also be reflectable, but does not need to be a Component #[derive(Default, Reflect)] #[reflect(Default)] enum BiomeType { #[default] Unknown, Forest, Plain, Mountain, Desert, } // Register your top-level struct in the Bevy registry fn main() { App::new() .register_type::(); } ``` -------------------------------- ### Respawn/Reload a Tiled Map Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/spawn_reload.md Reloads the current Tiled map asset, resetting all child entities to their original state while preserving the map entity and its components. Useful for level resets. ```rust fn respawn_map( mut commands: Commands, map_query: Query>, ) { if let Ok(entity) = map_query.single() { commands.entity(entity).insert(RespawnTiledMap); } } ``` -------------------------------- ### Update External Type Usage in Rust Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_10.md When using types from external crates like rs-tiled, geo, or regex, reference them through their dedicated modules in bevy_ecs_tiled. This prevents naming conflicts and clarifies type usage. ```rust use bevy_ecs_tiled::prelude::* // For external types, use their module: let tiled_id: tiled::TiledId = 10; ``` -------------------------------- ### Update Physics Collider Event Handling Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_12.md In v0.12, only a single ColliderCreated event is sent per physics object. Update your event handlers to expect this change and access the parent entity directly from the event. ```rust // Old: Could receive multiple ColliderCreated events per object fn on_collider_created(mut events: EventReader) { for event in events.read() { // Handle each collider individually } } // New: Single event per object, check the collider structure in physics backend fn on_collider_created(mut events: EventReader) { for event in events.read() { // Event now provides direct reference to parent entity let parent = event.parent_entity; } } ``` -------------------------------- ### Disable Geometry Simplification for an Object Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/migrations/v0_12.md To prevent merging colliders for a specific Tiled object, insert the TiledPhysicsDisableGeometrySimplification component into its entity. ```rust // Prevent merging colliders for a specific object commands.entity(object_entity) .insert(TiledPhysicsDisableGeometrySimplification); ``` -------------------------------- ### Despawn a Tiled Map Source: https://github.com/adrien-bon/bevy_ecs_tiled/blob/main/book/src/guides/spawn_reload.md Removes a Tiled map entity and all its associated child entities (layers, tiles, objects). Use this to clear a map from the scene. ```rust pub fn despawn_map( mut commands: Commands, map_query: Query>, ) { // Iterate over all map entities for map in map_query.iter() { // Despawn the map entity and all its children commands.entity(map).despawn(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.