//! This example cycles through different kinds of orthogonal maps. use bevy::prelude::*; use bevy_ecs_tiled::prelude::*; use bevy_ecs_tilemap::prelude::*; mod helper; fn main() { App::new() // Bevy default plugins .add_plugins(DefaultPlugins) // Examples helper plugins: for this example, contains the logic to switch between maps .add_plugins(helper::HelperPlugin) // bevy_ecs_tilemap and bevy_ecs_tiled main plugins .add_plugins(TilemapPlugin) .add_plugins(TiledMapPlugin::default()) // Enable debug informations about Tiled objects position .add_plugins(TiledMapDebugPlugin::default()) // Add our systems and run the app! .add_systems(Startup, startup) .add_systems(Update, switch_map) .run(); } fn startup(mut commands: Commands, asset_server: Res) { commands.spawn(Camera2dBundle::default()); let default_callback: helper::assets::MapInfosCallback = |c| { c.insert(TiledMapSettings { layer_positioning: LayerPositioning::Centered, ..default() }); }; let mut mgr = helper::assets::AssetsManager::new(&mut commands); mgr.add_map(helper::assets::MapInfos::new( &asset_server, "finite.tmx", "A finite orthogonal map with a single external tileset", default_callback, )); mgr.add_map(helper::assets::MapInfos::new( &asset_server, "finite_embedded.tmx", "A finite orthogonal map with a single embedded tileset", default_callback, )); mgr.add_map(helper::assets::MapInfos::new( &asset_server, "infinite.tmx", "An infinite orthogonal map with a single external tileset", default_callback, )); mgr.add_map(helper::assets::MapInfos::new( &asset_server, "infinite_embedded.tmx", "An infinite orthogonal map with a single embedded tileset", default_callback, )); mgr.add_map(helper::assets::MapInfos::new( &asset_server, // For simplicity sake, we use two tilesets which actually use the same images // However, we can verify with the inspector that the map actually use tiles // from both tilesets "multiple_tilesets.tmx", "A finite orthogonal map with multiple external tilesets", default_callback, )); commands.insert_resource(mgr); } fn switch_map( mut commands: Commands, keyboard_input: Res>, mut mgr: ResMut, ) { if keyboard_input.just_pressed(KeyCode::Space) { mgr.cycle_map(&mut commands); } }