#Isometric sprite render order
1 messages · Page 1 of 1 (latest)
Nothing bevy specific, guessing just some specific math
@white bear thanks!
So im wondering how i can define some kind of kind function that is like "for each sprite, do this". I get that I could use ECS queries to query all sprite objects and set their z ordering based on some math principle. Or set the Z correctly upon creation of a sprite, and only change the Z ordering based on some math principle if there was a change detected in the Transform, to be more efficient. But I was wondering if there was some kind of deeper rendering thing i could tap into that lets me achieve this? Is doing it the ECS way more correct?
Hmm, not an expert on rendering, you could probably do it. But I'd try the simpler approach and just query transforms and do whatever modification is needed on the z index. Until someone comes with a more clever approach
Ah. Well, to get back to the math, i have an idea but im not sure what the math would be for this. I was thinking that based on the position (x,y), the z should be some number in a range, lets say between 1.0 and 2.0. If the object is at the very top the Z would be 1.0, and if it were at the very bottom, it would be 2.0 (render on top of everything). Do i just..scale the Y value into that range? It feels like if an object has a greater Y it would be rendered behind u, and if it has a lesser y, it would be closer to the camera so it should be rendered first. Il probably just try it to see if that works at all but if not, i wonder what the actual math would be for this.
Try it out and see, but the articles in the above link seem really useful, they explain why and how
I honestly havent done any iso work yet so cant say anything at the top of my head
Yeah i took a look. One link dealt with converting 3D to ISO 2D and which of two overlapping objects should be rendered first. The other links were either broken or not direction to an actual article. But im more thinking about how to set Z for something depending on its own position, regardless of whether its overlapping or not. The (x,y,z) ? ( x0 + x - y , y0 - x/2 - y/2 + z ) equation might come in handy tho...
Yeah so my idea seems to be working.
Basically, u want to convert the Y value of a given translation to a Z value, such that as Y increases, Z gets closer and closer to 1. If Y is at the highest possible value for your world, Z should be equal to 1. And conversely it should be equal to 11 when its at the lowest possible value. I needed to figure out what the maximum Y value is for my world, which will depend on the constraints placed in the world. I then had to normalize that along with the input Y (which generates the new Z value) such that all possible values fall within the range: 0 - maximum_y. That way we dont have to worry about negative Y values.
I dont have any sprites that have holes in them, or sprites representing arches that other sprites can pass through. However, id imagine this trick wouldnt work on those kinds of sprites. If u want to keep using this trick with that kind of sprite, u need to split up that object into multiple sprites, so they each get handled separately and have their own Z value.
I dont have any sprites that have holes in them, or sprites representing arches that other sprites can pass through. However, id imagine this trick wouldnt work on those kinds of sprites. If u want to keep using this trick with that kind of sprite, u need to split up that object into multiple sprites, so they each get handled separately and have their own Z value.
I think this is the way people usually do this anyways, so you're on the right track