### Initializing Bevy App with LDTK Plugin (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet demonstrates the basic setup of a Bevy application, including the integration of the `bevy_ecs_ldtk` plugin. It shows the `App::new()` builder pattern and a placeholder for additional app builders, followed by the `run()` method to start the application. The `{{#include ...}}` line suggests further configuration is loaded from an external file. ```Rust # use bevy_ecs_ldtk::prelude::*; fn main() { App::new() // other App builders {{#include ../../../../examples/tile_based_game.rs:24}} .run(); } ``` -------------------------------- ### Main Application Setup in Bevy Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This `main` function initializes a new Bevy application. It sets up the core game loop and system execution. The `// other App builders` comment indicates that additional Bevy plugins, resources, or systems would typically be added here to configure the game, such as asset loading, input handling, and game state management, before the application starts running. ```Rust fn main() { App::new() // other App builders .run(); } ``` -------------------------------- ### Running Generic Example with Bevy ECS LDtk (Shell) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/README.md This command provides a general way to run any of the examples available in the `bevy_ecs_ldtk` repository. Users should replace `example-name` with the specific name of the example they wish to run, such as 'platformer' or other tutorials. ```Shell $ cargo run --example example-name ``` -------------------------------- ### Spawning Camera and LdtkWorldBundle on Startup - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/spawn-your-ldtk-project-in-bevy.md This snippet defines a startup system (`setup`) that spawns a 2D camera with a doubled scale and an `LdtkWorldBundle` by loading the LDtk project from the asset server. The `setup` system is then registered to run once at application startup. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) .add_plugins(LdtkPlugin) .add_systems(Startup, setup) .run(); } fn setup(mut commands: Commands, asset_server: Res) { let ldtk_handle = asset_server.load("assets/tile-based-game.ldtk"); commands.spawn(Camera2dBundle { transform: Transform::from_xyz(640.0, 360.0, 0.0).with_scale(Vec3::splat(2.0)), ..Default::default() }); commands.spawn(LdtkWorldBundle { ldtk_handle, ..Default::default() }); } ``` -------------------------------- ### Running Bevy ECS LDtk Tile-Based Game Example (Bash) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/README.md This command executes the `tile_based_game` example from the `bevy_ecs_ldtk` repository. The `--release` flag compiles the example in release mode, optimizing for performance and reducing execution time. ```Bash $ cargo run --example tile_based_game --release ``` -------------------------------- ### Defining LevelWalls Resource and App Setup (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This code block defines the `LevelWalls` resource, which stores wall locations as a `HashSet` along with level dimensions. It also includes a `main` function for Bevy app setup, similar to previous examples, and a placeholder for additional code from `tile_based_game.rs` (lines 77-92), which likely contains the `LevelWalls` struct definition and its `in_wall` method. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; use std::collections::HashSet; fn main() { App::new() // other App builders {{#include ../../../../examples/tile_based_game.rs:25}} .run(); } {{#include ../../../../examples/tile_based_game.rs:77:92}} ``` -------------------------------- ### Running the Collectathon Example Game (Bash) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/examples/collectathon/README.md This command executes the 'collectathon' example game in release mode using Cargo, Rust's package manager. It compiles and runs the game, providing a performance-optimized version for play. ```bash cargo run --example collectathon --release ``` -------------------------------- ### Configuring LevelSelection and Neighbor Loading in Bevy ECS LDtk Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/explanation/level-selection.md This snippet demonstrates how to initialize the `LevelSelection` resource to specify a starting level (index 0) and configure `LdtkSettings` to enable loading of neighboring levels. This setup is crucial for GridVania/Free-style worlds where seamless transitions between levels are desired. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; fn main() { App::new() // other App builders .insert_resource(LevelSelection::index(0)) .insert_resource(LdtkSettings { level_spawn_behavior: LevelSpawnBehavior::UseWorldTranslation { load_level_neighbors: true }, ..default() }) .run(); } ``` -------------------------------- ### Running Platformer Example with Bevy ECS LDtk (Shell) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/README.md This command executes the 'platformer' example included with the `bevy_ecs_ldtk` plugin. It compiles and runs the example in release mode, demonstrating the plugin's capabilities for creating platformer games using LDtk levels and Bevy ECS. ```Shell cargo run --example platformer --release ``` -------------------------------- ### Including Tile-Based Game Configuration (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet is a placeholder for including a specific section of code from the `tile_based_game.rs` example file, specifically lines 69 to 75. It likely contains additional Bevy app configuration or system definitions relevant to the tile-based game example, but the exact content is not provided directly. ```Rust {{#include ../../../../examples/tile_based_game.rs:69:75}} ``` -------------------------------- ### Defining Goal Component and Bundle (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet provides the necessary imports for Bevy and `bevy_ecs_ldtk`. The `{{#include ...}}` line indicates where the definition for the `GoalBundle` and its associated marker component, similar to `PlayerBundle`, would be included from the `tile_based_game.rs` example file (lines 57-67). This is crucial for identifying the goal in the game. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; {{#include ../../../../examples/tile_based_game.rs:57:67}} ``` -------------------------------- ### Defining Wall Entity Bundle for Collision (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet defines the `Wall` marker component and the `WallBundle` struct. The `WallBundle` is designed for wall entities in LDtk, deriving `LdtkIntCell` to automatically receive a `GridCoords` component upon spawning. This setup is crucial for implementing tile-based collision detection by identifying wall locations based on their integer grid value (e.g., 1 for walls). ```Rust #[derive(Default, Component)] pub struct Wall; #[derive(Default, Bundle, LdtkIntCell)] pub struct WallBundle { wall: Wall, } ``` -------------------------------- ### Registering Unresolved Reference with LdtkEntity Bundle - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/create-bevy-relations-from-ldtk-entity-references.md Configures an `LdtkEntity` bundle to include the `UnresolvedMotherRef` component. This setup ensures that when an LDtk entity is spawned, the unresolved reference component is automatically added and populated using the previously defined construction method. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # {{ #include ../../../examples/field_instances/mother.rs:10 }} # {{ #include ../../../examples/field_instances/mother.rs:11 }} # impl UnresolvedMotherRef { fn from_mother_field(_: &EntityInstance) -> UnresolvedMotherRef { todo!() } } {{ #include ../../../examples/field_instances/enemy.rs:7:8}} {{ #include ../../../examples/field_instances/enemy.rs:15:19}} ``` -------------------------------- ### Setting Up Minimal Bevy App with LdtkPlugin - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/spawn-your-ldtk-project-in-bevy.md This snippet initializes a basic Bevy application, adding `DefaultPlugins` configured for nearest texture filtering (suitable for pixel art) and integrating `LdtkPlugin` for LDtk project support. It sets up the core application structure. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins.set(ImagePlugin::default_nearest())) .add_plugins(LdtkPlugin) .run(); } ``` -------------------------------- ### Selecting Initial LDtk Level - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/spawn-your-ldtk-project-in-bevy.md This snippet demonstrates how to set the initial level to be spawned by the `LdtkPlugin` by inserting the `LevelSelection` resource. It uses `LevelSelection::index(0)` to select the first level (0-indexed) of the loaded LDtk project. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(LdtkPlugin) .insert_resource(LevelSelection::index(0)) .run(); } ``` -------------------------------- ### Populating LevelWalls Resource System (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This code block sets up a Bevy system responsible for populating the `LevelWalls` resource. It listens for `LevelEvent::Spawned` to gather `GridCoords` of `Wall` entities and uses `LdtkProject` data to determine level dimensions. The snippet includes necessary boilerplate for `LevelWalls` and other components, and placeholders for the actual system registration and implementation. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # use std::collections::HashSet; # const GRID_SIZE: i32 = 16; # #[derive(Default, Resource)] # struct LevelWalls { # wall_locations: HashSet, # level_width: i32, # level_height: i32, # } # impl LevelWalls { # fn in_wall(&self, grid_coords: &GridCoords) -> bool { # grid_coords.x < 0 # || grid_coords.y < 0 # || grid_coords.x >= self.level_width # || grid_coords.y >= self.level_height # || self.wall_locations.contains(grid_coords) # } # } # #[derive(Component)] # struct Wall; # fn move_player_from_input() {} # fn translate_grid_coords_entities() {} fn main() { App::new() // other App builders {{#include ../../../../examples/tile_based_game.rs:15:20}} ) ) .run(); } {{#include ../../../../examples/tile_based_game.rs:131:159}} ``` -------------------------------- ### Implementing Player Movement Collision Check (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This code snippet provides the necessary context for updating the `move_player_from_input` system. It includes the `LevelWalls` resource definition and its `in_wall` method, along with a `Player` component. The `{{#include ...}}` line indicates where the actual logic for checking player movement against wall locations using the `LevelWalls` resource would be inserted. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # use std::collections::HashSet; # #[derive(Component)] # struct Player; # #[derive(Default, Resource)] # struct LevelWalls { # wall_locations: HashSet, # level_width: i32, # level_height: i32, # } # impl LevelWalls { # fn in_wall(&self, grid_coords: &GridCoords) -> bool { # grid_coords.x < 0 # || grid_coords.y < 0 # || grid_coords.x >= self.level_width # || grid_coords.y >= self.level_height # || self.wall_locations.contains(grid_coords) # } # } {{#include ../../../../examples/tile_based_game.rs:94:117}} ``` -------------------------------- ### Initializing LevelSet from IIDs (Bevy ECS LDTK 0.9) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This code demonstrates the updated method for creating a `LevelSet` in `bevy_ecs_ldtk` version 0.9 using the `LevelSet::from_iids` associated function. This approach simplifies initialization by accepting an array of string slices, which are automatically converted into the internal `LevelIid` representation. ```Rust # use bevy_ecs_ldtk::prelude::*; # fn f() { // 0.9 let level_set = LevelSet::from_iids( [ "e5eb2d73-60bb-4779-8b33-38a63da8d1db", "855fab73-2854-419f-a3c6-4ed8466592f6", ] ); # } ``` -------------------------------- ### Defining LDtk Entity Bundles for Sprites - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/spawn-your-ldtk-project-in-bevy.md This snippet defines `PlayerBundle` and `GoalBundle` structs, deriving `Default`, `Bundle`, and `LdtkEntity`. The `#[sprite_sheet]` attribute on the `sprite_sheet: Sprite` field instructs `bevy_ecs_ldtk` to spawn these entities with sprites identical to their editor visuals. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { #[sprite_sheet] sprite_sheet: Sprite, } #[derive(Default, Bundle, LdtkEntity)] struct GoalBundle { #[sprite_sheet] sprite_sheet: Sprite, } ``` -------------------------------- ### Defining Player Components: GridCoords and Player Marker (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet defines the `Player` marker component and the `PlayerBundle` struct. The `PlayerBundle` includes `GridCoords` for tile-based positioning, automatically populated by `bevy_ecs_ldtk` via the `#[grid_coords]` attribute, and a `Player` marker component for easy querying. It also includes standard `EntityInstance` and `SpriteSheetBundle` for LDtk entity spawning. ```Rust #[derive(Default, Component)] pub struct Player; #[derive(Default, Bundle, LdtkEntity)] pub struct PlayerBundle { #[grid_coords] pub grid_coords: GridCoords, pub player: Player, #[from_entity_instance] entity_instance: EntityInstance, #[sprite_sheet_bundle] sprite_sheet_bundle: SpriteSheetBundle, } ``` -------------------------------- ### Implementing Tile-Based Player Movement (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This system, `move_player_from_input`, processes WASD keyboard input to update the player's `GridCoords`. It queries for the player's `GridCoords` component and modifies it based on the pressed key, effectively moving the player one tile in the corresponding direction. This system is intended to be added to Bevy's `Update` schedule. ```Rust fn move_player_from_input( mut player_query: Query<&mut GridCoords, With>, input: Res>, ) { let mut player_grid_coords = player_query.single_mut(); if input.just_pressed(KeyCode::W) { player_grid_coords.y += 1; } else if input.just_pressed(KeyCode::A) { player_grid_coords.x -= 1; } else if input.just_pressed(KeyCode::S) { player_grid_coords.y -= 1; } else if input.just_pressed(KeyCode::D) { player_grid_coords.x += 1; } } ``` -------------------------------- ### Loading LdtkProject with .into() in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.10-to-0.11.md This snippet demonstrates the change in loading `LdtkProject` assets. Due to Bevy 0.15's restriction on `Handle` as components, the `asset_server.load()` call now requires `.into()` to convert the `Handle` into an `LdtkProjectHandle`. ```Rust // 0.10 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(LdtkWorldBundle { ldtk_handle: asset_server.load("my_project.ldtk"), ..Default::default() }); } ``` ```Rust // 0.11 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; fn setup(mut commands: Commands, asset_server: Res) { commands.spawn(LdtkWorldBundle { ldtk_handle: asset_server.load("my_project.ldtk").into(), ..Default::default() }); } ``` -------------------------------- ### Initializing LevelSet with String IIDs (Bevy ECS LDTK 0.8) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This snippet illustrates the manual construction of a `LevelSet` in `bevy_ecs_ldtk` version 0.8. It involves creating a `LevelSet` struct and populating its `iids` field with a `HashSet` of `String` identifiers. ```Rust // 0.8 let level_set = LevelSet { iids: [ "e5eb2d73-60bb-4779-8b33-38a63da8d1db".to_string(), "855fab73-2854-419f-a3c6-4ed8466592f6".to_string(), ].into_iter().collect(), } ``` -------------------------------- ### Querying LdtkProject with LdtkProjectHandle in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.10-to-0.11.md This snippet shows how to update queries that previously used `Handle`. In Bevy 0.15+, `Handle` cannot be used directly as a component in queries, so it must be replaced with `LdtkProjectHandle`. This type acts as a drop-in replacement for querying purposes. ```Rust // 0.10 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; fn respawn_world( mut commands: Commands, ldtk_projects: Query>>, input: Res>, ) { if input.just_pressed(KeyCode::KeyR) { commands.entity(ldtk_projects.single()).insert(Respawn); } } ``` ```Rust // 0.11 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; fn respawn_world( mut commands: Commands, ldtk_projects: Query>, input: Res>, ) { if input.just_pressed(KeyCode::KeyR) { commands.entity(ldtk_projects.single()).insert(Respawn); } } ``` -------------------------------- ### Checking Player-Goal Collision for Level Transition (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet provides the foundational components (`Player`, `Goal`) and function declarations (`move_player_from_input`, `translate_grid_coords_entities`) required for a system that detects when a player reaches a goal. The system would query for `Changed` on the player and, upon a match with the goal's `GridCoords`, update the `LevelSelection` resource to advance to the next level. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # #[derive(Component)] # struct Player; # #[derive(Component)] # struct Goal; # fn move_player_from_input() {} # fn translate_grid_coords_entities() {} ``` -------------------------------- ### Implementing Default for LdtkEntity Bundles in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets illustrate the new requirement in `bevy_ecs_ldtk` 0.9 for `LdtkEntity` types to implement `Default` directly on the bundle, unlike 0.8 where it was sufficient for the contained components to implement `Default`. ```Rust // 0.8 #[derive(Bundle, LdtkEntity)] struct MyBundle { component: MyComponentThatImplementsDefault, } ``` ```Rust # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; # #[derive(Default, Component)] # struct MyComponentThatImplementsDefault; // 0.9 #[derive(Default, Bundle, LdtkEntity)] struct MyBundle { component: MyComponentThatImplementsDefault, } ``` -------------------------------- ### Querying LDTK Project and Level Data in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/make-level-selection-follow-player.md This code snippet illustrates how to access `LdtkProject` asset data and individual `Level` data for spawned levels. It queries for the `LdtkProjectHandle` and then uses it to look up raw level data via `LevelIid` components, which is essential for determining level bounds and updating `LevelSelection`. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # #[derive(Component)] # struct Player; {{ #include ../../../examples/collectathon/player.rs:59:74 }} } } Ok(()) } ``` -------------------------------- ### Synchronizing Transform with GridCoords (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This system, `update_transform_from_grid_coords`, ensures that an entity's visual `Transform` is synchronized with its `GridCoords` component. It queries for entities with both components and uses `GridCoords::to_translation` to convert the grid position into world coordinates, applying the correct tile size obtained from the `LdtkProject`. This system should run after `GridCoords` updates, typically in `PostUpdate`. ```Rust fn update_transform_from_grid_coords( mut query: Query<(&GridCoords, &mut Transform)>, ldtk_project_query: Query<&LdtkProject>, ) { let ldtk_project = ldtk_project_query.single(); let tile_size = ldtk_project.level_grid_size as f32; for (grid_coords, mut transform) in &mut query { transform.translation = grid_coords.to_translation(tile_size); } } ``` -------------------------------- ### Configuring Bevy App for Level Neighbors in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/make-level-selection-follow-player.md This snippet demonstrates how to configure the Bevy application to enable loading of level neighbors using `bevy_ecs_ldtk`. It shows the basic structure of a Bevy `App` initialization, indicating where the `bevy_ecs_ldtk` plugin and its related configurations would be added to ensure levels adjacent to the current `LevelSelection` are also spawned. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; fn main() { App::new() // Other App builders {{ #include ../../../examples/collectathon/main.rs:13:18 }} .run(); } ``` -------------------------------- ### Implementing the Blueprint Pattern for Player Entities in Bevy ECS LDTK Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/explanation/game-logic-integration.md This Rust code demonstrates the 'blueprint pattern' for handling LDTK entities in Bevy. It shows how to register a custom `LdtkEntity` bundle (`PlayerBundle`) with a marker component (`Player`), allowing a separate system (`process_player`) to query for newly added players using `Added` for post-processing, such as adding child entities. This approach simplifies entity identification and manipulation compared to filtering by instance IDs. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; fn main() { App::new() // other App builders .register_ldtk_entity::("Player") .add_systems(Update, process_player) .run(); } #[derive(Default, Component)] struct PlayerChild; #[derive(Default, Component)] struct Player; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { player: Player, #[sprite] sprite: Sprite, } fn process_player( mut commands: Commands, new_players: Query>, ) { for player_entity in new_players.iter() { commands .spawn(PlayerChild) .insert(ChildOf(player_entity)); } } ``` -------------------------------- ### Registering LDtk Entity Bundles with App - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/spawn-your-ldtk-project-in-bevy.md This snippet registers the custom `PlayerBundle` and `GoalBundle` with the Bevy application using `register_ldtk_entity`. This tells the `LdtkPlugin` to use these specific bundles when spawning entities with the corresponding LDtk identifiers ('Player' and 'Goal'). ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { #[sprite_sheet] sprite_sheet: Sprite, } #[derive(Default, Bundle, LdtkEntity)] struct GoalBundle { #[sprite_sheet] sprite_sheet: Sprite, } fn main() { App::new() .add_plugins(DefaultPlugins) .add_plugins(LdtkPlugin) .register_ldtk_entity::("Player") .register_ldtk_entity::("Goal") .run(); } ``` -------------------------------- ### Placeholder Function for Wall Location Caching in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/tutorials/tile-based-game/add-gameplay-to-your-project.md This snippet defines an empty placeholder function, `cache_wall_locations`. It is likely intended to be implemented later to store or process the locations of wall tiles within the game, possibly for collision detection or rendering optimization. ```Rust fn cache_wall_locations() {} ``` -------------------------------- ### Accessing Level Data from LdtkProject using LevelIid in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets show how to retrieve level data from the `LdtkProject` asset using the `LevelIid` component in `bevy_ecs_ldtk` 0.9. This replaces the direct access via `Handle` from 0.8 for data not within `layer_instances`. ```Rust // 0.8 fn print_level_uid(levels: Query>, level_assets: Res>) { for level_handle in &levels { let level_uid = level_assets.get(level_handle).unwrap().uid; println!("level w/ uid {level_uid}, is currently spawned"); } } ``` ```Rust # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; // 0.9 fn print_level_uid( levels: Query<&LevelIid>, projects: Query<&Handle>, project_assets: Res> ) { for level_iid in &levels { let only_project = project_assets.get(projects.single()).unwrap(); let level_uid = only_project.get_raw_level_by_iid(level_iid.get()).unwrap().uid; println!("level w/ uid {level_uid}, is currently spawned"); } } ``` -------------------------------- ### Defining PlayerBundle with LdtkSpriteSheetBundle (0.10) - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.9-to-0.10.md This snippet illustrates the updated `PlayerBundle` definition for `bevy_ecs_ldtk` version 0.10, reflecting the deprecation of `SpriteSheetBundle` in Bevy 0.14. `LdtkSpriteSheetBundle` is now used, maintaining the same functionality with the `#[sprite_sheet_bundle]` macro. ```Rust // 0.10 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { #[sprite_sheet_bundle] sprite_bundle: LdtkSpriteSheetBundle, #[grid_coords] grid_coords: GridCoords, } ``` -------------------------------- ### Registering Player Bundle with LdtkEntity in Bevy Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/explanation/game-logic-integration.md This snippet demonstrates how to register a custom Bevy `Bundle` (`PlayerBundle`) with `bevy_ecs_ldtk` using `register_ldtk_entity`. It shows the `LdtkEntity` derive macro for automatic bundle construction and the `#[sprite]` attribute for assigning a sprite based on the LDtk editor visual. This method is suitable for simple entity spawning. ```Rust use bevy::prelude::*; use bevy_ecs_ldtk::prelude::*; fn main() { App::new() // other App builders .register_ldtk_entity::("Player") .run(); } #[derive(Default, Component)] struct Player; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { player: Player, #[sprite] sprite: Sprite, } ``` -------------------------------- ### Creating LevelSet from Multiple IIDs (Bevy ECS LDTK 0.9) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This code demonstrates the `LevelSet::from_iids` method in `bevy_ecs_ldtk` version 0.9, which replaces `from_iid`. This new method is more flexible, allowing the creation of a `LevelSet` from any iterator of string slices, whether it's a single IID or multiple. ```Rust # use bevy_ecs_ldtk::prelude::*; # fn f() { // 0.9 let level_set = LevelSet::from_iids(["e5eb2d73-60bb-4779-8b33-38a63da8d1db"]); // or many.. let level_set = LevelSet::from_iids( [ "e5eb2d73-60bb-4779-8b33-38a63da8d1db", "855fab73-2854-419f-a3c6-4ed8466592f6", ] ); # } ``` -------------------------------- ### Post-processing LDtk Entity Instances in Bevy Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/explanation/game-logic-integration.md This system demonstrates how to manually process newly spawned `EntityInstance` components from LDtk. It queries for entities with `Added`, filters for a specific identifier ('Player'), and then inserts custom components (`Player`, `Sprite`, `Transform`) and spawns a child entity (`PlayerChild`). This approach provides greater control for complex spawning logic. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; #[derive(Default, Component)] struct PlayerChild; #[derive(Default, Component)] struct Player; fn process_player( mut commands: Commands, new_entity_instances: Query<(Entity, &EntityInstance, &Transform), Added>, assets: Res, ) { for (entity, entity_instance, transform) in new_entity_instances.iter() { if entity_instance.identifier == "Player".to_string() { commands .entity(entity) .insert(Player) .insert(( Sprite::from_image(assets.load("player.png")), *transform, )) .with_children(|commands| { commands.spawn(PlayerChild); }); } } } ``` -------------------------------- ### Illustrating Default Behavior Change for LdtkEntity in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This Rust snippet demonstrates the change in `Default` implementation behavior for `LdtkEntity`-derived bundles between `bevy_ecs_ldtk` 0.8 and 0.9. In 0.8, the field's `Default` was used, while in 0.9, the bundle's `Default` implementation takes precedence, leading to different component values upon entity spawning. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; #[derive(Component)] struct MyComponent(usize); impl Default for MyComponent { fn default() -> MyComponent { MyComponent(1) } } #[derive(Bundle, LdtkEntity)] struct MyBundle { component: MyComponent, } impl Default for MyBundle { fn default() -> MyBundle { MyBundle { component: MyComponent(2), } } } // In bevy_ecs_ldtk 0.8, the plugin would spawn an entity w/ MyComponent(1) // In bevy_ecs_ldtk 0.9, the plugin now spawns the entity w/ MyComponent(2) ``` -------------------------------- ### Implementing Post-Processing System for Reference Resolution - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/create-bevy-relations-from-ldtk-entity-references.md Develops a Bevy system that runs after entity spawning to resolve `Unresolved` references. It queries for entities with the `UnresolvedMotherRef` component, matches their LDtk iid to existing Bevy entities, and replaces the unresolved component with the `Mother` relational component, establishing the final link. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # {{ #include ../../../examples/field_instances/mother.rs:10 }} # {{ #include ../../../examples/field_instances/mother.rs:11 }} # {{ #include ../../../examples/field_instances/mother.rs:26 }} # {{ #include ../../../examples/field_instances/mother.rs:27 }} {{ #include ../../../examples/field_instances/mother.rs:29:51 }} ``` -------------------------------- ### Using LevelSet for Advanced Level Selection in Bevy ECS LDtk Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/explanation/level-selection.md This snippet illustrates the usage of the `LevelSet` component for lower-level, more granular control over which levels are spawned. Unlike `LevelSelection`, `LevelSet` allows specifying a set of levels by their iids and is ideal for per-world level management or complex spawning behaviors not covered by the global resource. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; {{#include ../../../examples/level_set.rs:28:50}} # fn main() {} ``` -------------------------------- ### Creating LevelSet from Single IID (Bevy ECS LDTK 0.8) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This snippet shows how to create a `LevelSet` from a single IID string using the `LevelSet::from_iid` associated function in `bevy_ecs_ldtk` version 0.8. This method was designed for convenience when only one level IID was needed. ```Rust // 0.8 let level_set = LevelSet::from_iid("e5eb2d73-60bb-4779-8b33-38a63da8d1db"); ``` -------------------------------- ### Retrieving LoadedLevel Data for Internal Levels in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This Rust snippet demonstrates how to retrieve complete `LoadedLevel` data for internal-levels projects in `bevy_ecs_ldtk` 0.9. It uses the `LevelIid` and `LdtkProject` to access detailed level information, including layer instances, via the `as_standalone()` method. ```Rust # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; // 0.9, w/ internal_levels enabled fn print_level_uid( levels: Query<&LevelIid>, projects: Query<&Handle>, project_assets: Res> ) { for level_iid in &levels { let only_project = project_assets.get(projects.single()).unwrap(); let layer_count = only_project .as_standalone() .get_loaded_level_by_iid(level_iid.get()) .unwrap() .layer_instances() .len(); println!("level has {layer_count} layers"); } } ``` -------------------------------- ### Respawning the Entire World in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/respawn-levels-and-worlds.md This snippet demonstrates how to respawn the entire game world by querying for the world's entity and inserting the `Respawn` component. This is particularly useful for games with a single world, enabling a full restart of all world-related entities. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; fn respawn_world( mut commands: Commands, worlds: Query>, input: Res>, ) -> Result { if input.just_pressed(KeyCode::KeyR) { commands.entity(worlds.single()?).insert(Respawn); } Ok(()) } ``` -------------------------------- ### Calculating Level Bounds with GlobalTransform in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/make-level-selection-follow-player.md This snippet demonstrates how to calculate the bounding `Rect` for a spawned LDTK level. It uses the `GlobalTransform` of the level entity for the lower-left corner and adds the level's pixel width (`px_wid`) and height (`pix_hei`) from the raw `Level` data to determine the upper-right corner, crucial for player collision detection and level selection. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::ldtk::Level; # fn foo(level_transform: &GlobalTransform, level: &Level) { {{ #include ../../../examples/collectathon/player.rs:76:85 }} # } ``` -------------------------------- ### Defining PlayerBundle with SpriteSheetBundle (0.9) - Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.9-to-0.10.md This snippet shows the `PlayerBundle` definition in `bevy_ecs_ldtk` version 0.9, where `SpriteSheetBundle` was used for sprite rendering. It demonstrates how the `#[sprite_sheet_bundle]` macro was applied to integrate sprite sheet functionality into an LDTK entity bundle. ```Rust // 0.9 #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { player: Player, #[sprite_sheet_bundle] sprite_bundle: SpriteSheetBundle, #[grid_coords] grid_coords: GridCoords, } ``` -------------------------------- ### Respawning Level by LevelSelection IID in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/respawn-levels-and-worlds.md This snippet demonstrates respawning a level based on the `LevelSelection` resource, assuming it's an `Iid` type. It iterates through spawned level entities to find the one matching the selected IID and then inserts the `Respawn` component to restart it. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; fn respawn_selected_level_by_iid( mut commands: Commands, level_selection: Res, levels: Query<(Entity, &LevelIid)>, input: Res>, ) -> Result { if input.just_pressed(KeyCode::KeyL) { if let LevelSelection::Iid(selected_iid) = *level_selection { for (level_entity, level_iid) in levels.iter() { if selected_iid == *level_iid { commands.entity(level_entity).insert(Respawn); break; } } } } Ok(()) } ``` -------------------------------- ### Selecting Level by Index (Bevy ECS LDTK 0.9) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This code demonstrates the updated method for creating a `LevelSelection` using the `LevelSelection::index` associated function in `bevy_ecs_ldtk` version 0.9. This function provides a more ergonomic way to select a level by its numerical index. ```Rust # use bevy_ecs_ldtk::prelude::*; # fn f() { // 0.9 let level_selection = LevelSelection::index(2); # } ``` -------------------------------- ### Migrating LdtkSpriteSheetBundle to Sprite in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.10-to-0.11.md This snippet illustrates the migration from `LdtkSpriteSheetBundle` to `Sprite` in `bevy_ecs_ldtk` due to Bevy 0.15's `Sprite` struct now handling `TextureAtlas` information. The `#[sprite_sheet_bundle]` macro is replaced by `#[sprite_sheet]` for defining sprite sheet bundles. ```Rust // 0.10 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { #[sprite_sheet_bundle] sprite_bundle: LdtkSpriteSheetBundle, #[grid_coords] grid_coords: GridCoords, } ``` ```Rust // 0.11 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; #[derive(Default, Bundle, LdtkEntity)] struct PlayerBundle { #[sprite_sheet] sprite_sheet: Sprite, #[grid_coords] grid_coords: GridCoords, } ``` -------------------------------- ### Enabling Internal Levels Feature in Cargo.toml Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This TOML snippet shows how to enable the `internal_levels` cargo feature for `bevy_ecs_ldtk` 0.9 when `default-features` are disabled. This feature is required for projects using internal levels if default features are not enabled. ```TOML # 0.8 bevy_ecs_ldtk = { version = "0.8", default-features = false, features = ["render"] } ``` ```TOML # 0.9 bevy_ecs_ldtk = { version = "0.9", default-features = false, features = ["render", "internal_levels"] } ``` -------------------------------- ### Enabling External Levels Feature in Cargo.toml Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This TOML snippet demonstrates how to enable the `external_levels` cargo feature for `bevy_ecs_ldtk` 0.9. This feature is not enabled by default and is necessary for projects that utilize external LDtk levels. ```TOML # 0.8 bevy_ecs_ldtk = "0.8" ``` ```TOML # 0.9 bevy_ecs_ldtk = { version = "0.9", features = ["external_levels"] } ``` -------------------------------- ### Printing Level Layer Count with Bevy ECS LDTK (0.9) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This Rust function demonstrates how to query `LevelIid` and `LdtkProject` assets to retrieve and print the number of layers in an external LDTK level. It showcases the use of `LdtkExternalLevel` to access detailed level information, relevant for `bevy_ecs_ldtk` version 0.9 with external levels enabled. ```Rust # use bevy::prelude::*; // 0.9, w/ external_levels enabled fn print_level_uid( levels: Query<&LevelIid>, projects: Query<&Handle>, project_assets: Res> level_assets: Res>, ) { for level_iid in &levels { let only_project = project_assets.get(projects.single()).unwrap(); let layer_count = only_project .as_parent() .get_external_level_by_iid(&level_assets, level_iid.get()) .unwrap() .layer_instances() .len(); println!("level has {layer_count} layers"); } } ``` -------------------------------- ### Selecting Level by Index (Bevy ECS LDTK 0.8) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This snippet illustrates how to create a `LevelSelection` by directly using the `LevelSelection::Index` enum variant with an integer index in `bevy_ecs_ldtk` version 0.8. This was used to select a level based on its numerical order. ```Rust // 0.8 let level_selection = LevelSelection::Index(2); ``` -------------------------------- ### Respawning Level by LdtkProject Asset Search in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/respawn-levels-and-worlds.md This advanced snippet demonstrates respawning a level by first resolving the `LevelSelection` against the `LdtkProject` asset data to find the correct `LevelIid`. It then iterates through spawned levels to match the resolved IID and inserts the `Respawn` component, providing a robust way to restart levels when `LevelSelection` type is uncertain. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; fn respawn_selected_level_from_project( mut commands: Commands, level_selection: Res, levels: Query<(Entity, &LevelIid)>, input: Res>, ldtk_projects: Query<&LdtkProjectHandle>, ldtk_project_assets: Res>, ) -> Result { if input.just_pressed(KeyCode::KeyL) { if let Some(only_project) = ldtk_project_assets.get(ldtk_projects.single()?) { let level_selection_iid = LevelIid::new( only_project .find_raw_level_by_level_selection(&level_selection) .expect("spawned level should exist in project") .iid .clone(), ); for (level_entity, level_iid) in levels.iter() { if level_selection_iid == *level_iid { commands.entity(level_entity).insert(Respawn); } } } } Ok(()) } ``` -------------------------------- ### Full System for Updating LevelSelection Based on Player Position in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/make-level-selection-follow-player.md This comprehensive system combines the logic for querying level data, calculating level bounds, and updating the `LevelSelection` resource. It checks if the player entity's position falls within the bounds of any spawned level and, if so, sets the `LevelSelection` to that level's `LevelIid`, enabling dynamic level traversal. ```Rust # use bevy::prelude::*; # use bevy_ecs_ldtk::prelude::*; # #[derive(Component)] # struct Player; {{ #include ../../../examples/collectathon/player.rs:59:93 }} ``` -------------------------------- ### Migrating LdtkAsset to LdtkProject in Bevy ECS LDtk Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets show the renaming of `LdtkAsset` to `LdtkProject` in `bevy_ecs_ldtk` 0.9. Systems interacting with LDtk project data must update their queries and resource access to use the new `LdtkProject` type. ```Rust // 0.8 fn do_some_processing_with_ldtk_data( worlds: Query<&Handle>, ldtk_assets: Res> ) { // do something } ``` ```Rust # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; // 0.9 fn do_some_processing_with_ldtk_data( worlds: Query<&Handle>, ldtk_assets: Res> ) { // do something } ``` -------------------------------- ### Accessing LdtkProject Data Fields in Rust Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets demonstrate the change in accessing fields of the `LdtkProject` (formerly `LdtkAsset`) in `bevy_ecs_ldtk` 0.9. Fields are now privatized and accessed via immutable accessor methods, with some method names differing from their 0.8 field counterparts. ```Rust // 0.8 let ldtk_json = ldtk_project.project; let tileset_map = ldtk_project.tileset_map; let int_grid_image_handle = ldtk_project.int_grid_image_handle; let level_map = ldtk_project.level_map; ``` ```Rust # use bevy_ecs_ldtk::prelude::*; # fn foo(ldtk_project: LdtkProject) { // 0.9 let ldtk_json = ldtk_project.json_data(); let tileset_map = ldtk_project.tileset_map(); let int_grid_image_handle = ldtk_project.int_grid_image_handle(); // the level_map is no longer available in the same way # } ``` -------------------------------- ### Migrating SpriteBundle to Sprite in Bevy ECS LDTK (Rust) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.10-to-0.11.md This snippet shows the migration from `SpriteBundle` to `Sprite` when used with the `#[sprite_bundle]` macro. In the updated version, the macro is renamed to `#[sprite]` to align with Bevy 0.15 changes. ```Rust // 0.10 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; #[derive(Bundle, LdtkEntity, Default)] pub struct Player { player: PlayerComponent, health: Health, #[sprite_bundle] sprite_bundle: SpriteBundle, } ``` ```Rust // 0.11 # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; #[derive(Bundle, LdtkEntity, Default)] pub struct Player { player: PlayerComponent, health: Health, #[sprite] sprite: Sprite, } ``` -------------------------------- ### Selecting Level by IID (Bevy ECS LDTK 0.9) Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md This code demonstrates the updated method for creating a `LevelSelection` using the `LevelSelection::iid` associated function in `bevy_ecs_ldtk` version 0.9. This function provides a more ergonomic way to select a level by its IID, accepting a string slice. ```Rust # use bevy_ecs_ldtk::prelude::*; # fn f() { // 0.9 let level_selection = LevelSelection::iid("e5eb2d73-60bb-4779-8b33-38a63da8d1db"); # } ``` -------------------------------- ### Migrating Level Accessor Methods in Bevy ECS LDtk Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets illustrate the redefinition and movement of level accessing methods in `bevy_ecs_ldtk` 0.9. Methods like `iter_levels` and `get_level` have been renamed and moved to new traits like `RawLevelAccessor` and `LevelMetadataAccessor`. ```Rust // 0.8 ldtk_json.iter_levels(); ldtk_asset.iter_levels(); ldtk_asset.get_level(&LevelSelection::Uid(24)); ``` ```Rust # use bevy_ecs_ldtk::{prelude::*, ldtk::LdtkJson}; # fn foo(ldtk_json: LdtkJson, ldtk_project: LdtkProject) { // 0.9 // in `RawLevelAccessor` trait: ldtk_json.iter_raw_levels(); ldtk_project.iter_raw_levels(); // in `LevelMetadataAccessor` trait ldtk_project.find_raw_level_by_level_selection(&LevelSelection::Uid(24)); # } ``` -------------------------------- ### Querying Level Entities with LevelIid in Bevy ECS LDtk Source: https://github.com/trouv/bevy_ecs_ldtk/blob/main/book/src/how-to-guides/migration-guides/migrate-from-0.8-to-0.9.md These Rust snippets illustrate the change in how level entities are identified in `bevy_ecs_ldtk` 0.9. Instead of a `Handle`, level entities now have a `LevelIid` component, which should be used for querying them. ```Rust // 0.8 fn print_level_entity(levels: Query>>) { for entity in &levels { println!("level entity {:?} is currently spawned", entity); } } ``` ```Rust # use bevy_ecs_ldtk::prelude::*; # use bevy::prelude::*; // 0.9 fn print_level_entity(levels: Query>) { for entity in &levels { println!("level entity {:?} is currently spawned", entity); } } ```