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

Unable to swap positions of tiles. #422

Closed
Gnamra opened this issue Apr 18, 2023 · 1 comment
Closed

Unable to swap positions of tiles. #422

Gnamra opened this issue Apr 18, 2023 · 1 comment

Comments

@Gnamra
Copy link

Gnamra commented Apr 18, 2023

Using the following code I am unable to swap the position of two tiles, in my project only one of the tiles seem to move, leaving a blank space. The code is mostly made up of code I copied from other examples, and I've attached a projected stripped of all of the unnecessary code that should compile, run and show the issue.

fn select_tile_input(
    mut commands: Commands,
    mouse_input: Res<Input<MouseButton>>,
    mut highlighted_tile_q: Query<(Entity, &mut TilePos), (With<Highlighted>, Without<Selected>)>,
    mut selected_tile_q: Query<(Entity, &mut TilePos), With<Selected>>,
) {
    if mouse_input.just_pressed(MouseButton::Left) {
        if let Ok((highlighted_tile_entity, mut highlighted_tile_pos)) =
            highlighted_tile_q.get_single_mut()
        {
            if let Ok((selected_tile_entity, mut selected_tile_pos)) =
                selected_tile_q.get_single_mut()
            {
                let temp_pos = selected_tile_pos.clone();
                *selected_tile_pos = highlighted_tile_pos.clone();
                *highlighted_tile_pos = temp_pos.clone();

                commands.entity(selected_tile_entity).remove::<Selected>();

            } else {
                commands
                    .entity(highlighted_tile_entity)
                    .insert(Selected);
            }
        }
    }
}

swap_tiles.zip

@Gnamra Gnamra closed this as completed May 11, 2023
@LilithHohman
Copy link

I was just wondering if you found a solution to this issue? I've encountered the same problem when moving tiles around, documented here: #559

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

2 participants