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

Parent scale.z affects child sprite z-index #4149

Open
SecretPocketCat opened this issue Mar 8, 2022 · 5 comments
Open

Parent scale.z affects child sprite z-index #4149

SecretPocketCat opened this issue Mar 8, 2022 · 5 comments
Labels
A-Hierarchy Parent-child entity hierarchies A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@SecretPocketCat
Copy link
Contributor

SecretPocketCat commented Mar 8, 2022

Bevy version

0.6.1

Operating system & version

Win 11

What you did

Spawned a parented sprite and change the parent's scale.z to something other than 1.0

What you expected to happen

Z-index of a sprite wouldn't be affected at all or the transform of the sprite would affect it as well.

What actually happened

It's affected by the parent transforms

Additional information

Repro
https://github.com/SecretPocketCat/bevy_issue_repro/blob/sprite_index_scale/src/main.rs
(the expected order from bottom would be red, green, blue)
2022-03-08 11_18_46-bevy

@SecretPocketCat SecretPocketCat added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 8, 2022
@james7132 james7132 added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 8, 2022
@lukors
Copy link
Contributor

lukors commented Mar 9, 2022

Isn't this behavior expected considering the sprite exists in 3d?

Isn't what you're referring to as "z index" actually just the Z position in 3d?

Or am I misunderstanding something?

@SecretPocketCat
Copy link
Contributor Author

SecretPocketCat commented Mar 9, 2022

@lukors
My issue is that only the parent.z scale affects the final z position, but not the transform of the sprite itself.

@alice-i-cecile
Copy link
Member

My opinion here is that this is a clear and compelling argument in favor of dedicated Transform2D types. This behavior is very surprising to beginners, and just adds to the friction of trying to make 2D games using 3D transforms.

@SecretPocketCat
Copy link
Contributor Author

That would be great.

@alice-i-cecile alice-i-cecile added the A-Hierarchy Parent-child entity hierarchies label Apr 4, 2022
@pmikolajek
Copy link

As a newcomer who just stumbled on this and spent some time figuring it out, here's how I would have expected this to work for 2D:

  • translation Z affects the z-index
  • scale doesn't affect z-index at all.

This would also be consistent with the docs in transform.rs, which mention z-ordering for translation but not for scale. As it is, it really is not clear at all how translation, scale, and child entities interact when it comes to z-index calculation. (Incidentally, is there a write-up about that somewhere, without looking through the source?)

I don't know how that would play with the larger implementation or 3D handling. It's just what would fit my initial, intuitive model.

github-merge-queue bot pushed a commit that referenced this issue Mar 13, 2024
# Objective

Scaling `z` by anything but `1.0` in 2d can only lead to bugs and
confusion. See #4149.

## Solution

Use a `Vec2` for the paddle size const, and add a scale of `1.0` later.
This matches the way `BRICK_SIZE` is defined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Hierarchy Parent-child entity hierarchies A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
5 participants