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

examples/clamped_border.rs should render square at true center #42

Open
MeoMix opened this issue Aug 18, 2023 · 0 comments
Open

examples/clamped_border.rs should render square at true center #42

MeoMix opened this issue Aug 18, 2023 · 0 comments

Comments

@MeoMix
Copy link

MeoMix commented Aug 18, 2023

Hello! :D

I am working on creating a follow-up response to you regarding the PR I proposed a few months ago.

In attempting to recreate my issue I realized that I was experiencing confusion due to an unexpected example.

This is the code that is currently used to generate a visually pleasing square of squares:

    let n = 20;
    let spacing = 50.;
    let offset = spacing * n as f32 / 2.;
    let custom_size = Some(Vec2::new(spacing, spacing));
    for x in 0..n {
        for y in 0..n {
            let x = x as f32 * spacing - offset;
            let y = y as f32 * spacing - offset;
            let color = Color::hsl(240., random::<f32>() * 0.3, random::<f32>() * 0.3);
            commands.spawn(SpriteBundle {
                sprite: Sprite {
                    color,
                    custom_size,
                    ..default()
                },
                transform: Transform::from_xyz(x, y, 0.),
                ..default()
            });
        }
    }

This square appears approximately in the center of the screen, but it's not true center. This is because we're spawning multiple sprites, rather than one large sprite, and each sprite is being added with the default center anchoring.

In contrast, consider this code:

    commands.spawn(SpriteBundle {
        transform: Transform::from_xyz(0.0, 0.0, 0.0),
        sprite: Sprite {
            color: Color::BLUE,
            custom_size: Some(Vec2::splat(spacing * n as f32)),
            ..default()
        },
        ..default()
    });

Here we generate a square which is the same dimensions and spawn it at 0,0 with a center anchor.

Visually, here are the outputs:

image

and we see that these two squares, while taking similar dimensions, have varying alignment. I find this to be extremely confusing given the context of attempting to verify the efficacy of boundary clamping.

I would expect that if I set projection.scale = 1.0 / (viewport.width / (spacing * n as f32)) that the square would be centered, but it is slightly off center, which gives the impression that potentially something is going awry with bounding logic.

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