Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tiled helper map location propagation #501

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions examples/helpers/tiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::sync::Arc;

use bevy::{
asset::{io::Reader, AssetLoader, AssetPath, AsyncReadExt},
hierarchy::BuildChildren,
log,
prelude::{
Added, Asset, AssetApp, AssetEvent, AssetId, Assets, Bundle, Commands, Component,
Expand Down Expand Up @@ -200,7 +201,7 @@ pub fn process_loaded_maps(
mut map_events: EventReader<AssetEvent<TiledMap>>,
maps: Res<Assets<TiledMap>>,
tile_storage_query: Query<(Entity, &TileStorage)>,
mut map_query: Query<(&Handle<TiledMap>, &mut TiledLayersStorage)>,
mut map_query: Query<(Entity, &Handle<TiledMap>, &mut TiledLayersStorage)>,
new_maps: Query<&Handle<TiledMap>, Added<Handle<TiledMap>>>,
) {
let mut changed_maps = Vec::<AssetId<TiledMap>>::default();
Expand Down Expand Up @@ -230,7 +231,7 @@ pub fn process_loaded_maps(
}

for changed_map in changed_maps.iter() {
for (map_handle, mut layer_storage) in map_query.iter_mut() {
for (map_entity, map_handle, mut layer_storage) in map_query.iter_mut() {
// only deal with currently changed map
if map_handle.id() != *changed_map {
continue;
Expand Down Expand Up @@ -315,6 +316,9 @@ pub fn process_loaded_maps(
let mut tile_storage = TileStorage::empty(map_size);
let layer_entity = commands.spawn_empty().id();

// Make layer entities transform relative to the map transform
commands.entity(map_entity).add_child(layer_entity);

for x in 0..map_size.x {
for y in 0..map_size.y {
// Transform TMX coords into bevy coords.
Expand Down Expand Up @@ -365,6 +369,9 @@ pub fn process_loaded_maps(
})
.id();
tile_storage.set(&tile_pos, tile_entity);
// Make tiles transform relative to layer transform,
// to ensure they have correct world_pos aligned with drawn location
commands.entity(layer_entity).add_child(tile_entity);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiles don't have bevy transforms. This wont do what you want it to here. Due to how bevy's transform propagation works it would be incredible slow to have each tile have a bevy transform so I can't recommend that.

}
}

Expand Down