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

Setting RenderLayers for the grids #235

Open
musjj opened this issue Oct 11, 2023 · 1 comment
Open

Setting RenderLayers for the grids #235

musjj opened this issue Oct 11, 2023 · 1 comment

Comments

@musjj
Copy link

musjj commented Oct 11, 2023

I'm using bevy_ecs_ldtk and I'm trying to set the render layer (for offscreen camera purposes) for the spawned grids, but I'm having trouble making it work. I tried setting it in the bundle:

#[derive(Component, Default)]
pub struct Wall;

#[derive(Bundle, LdtkIntCell)]
pub struct WallBundle {
    wall: Wall,
    layer: RenderLayers,
}

impl Default for GroundBundle {
    fn default() -> Self {
        Self {
            wall: Wall,
            layer: RenderLayers::layer(1),
        }
    }
}

But it doesn't work. I also tried putting it alongside the world bundle:

commands.spawn((
    LdtkWorldBundle {
        ldtk_handle: asset_server.load("tilemap.ldtk"),
        ..default()
    },
    RenderLayers::layer(1),
));

But it's also not working. Is there a proper way of doing this?

@musjj
Copy link
Author

musjj commented Oct 11, 2023

Figured out a solution:

fn add_layer(
    mut commands: Commands,
    wall_query: Query<&Parent, Added<Wall>>,
    parent_query: Query<Entity, (With<Parent>, Without<Wall>)>,
) {
    for parent in ground_query.iter() {
        if let Ok(entity) = parent_query.get(parent.get()) {
            commands.entity(entity).insert(RenderLayers::layer(1));
        }
    }
}

But this doesn't affect the background. I'm not sure how to target the background entity directly, so I'm currently using this hacky background:

fn fix_background(
    mut commands: Commands,
    query: Query<Entity, (With<Sprite>, Without<...>)>,
) {
    for sprite in query.iter() {
        commands.entity(sprite).insert(RenderLayers::layer(1));
    }
}

I had to litter it with Without<...> so that it doesn't affect any unwanted sprites. Is there a better way of doing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant