开发者

Complex depth sorting issue based on MC location

开发者 https://www.devze.com 2023-04-11 03:24 出处:网络
I need help rescuing a project concerning some extreme depth management. We\'re out of ideas! The project concerns stacking boxes of various sizes, each box is isometric - so thats where the depth co

I need help rescuing a project concerning some extreme depth management. We're out of ideas!

The project concerns stacking boxes of various sizes, each box is isometric - so thats where the depth comes in to play (we need to weave this box in front of that box, but on top of two boxes and below another, etc - anything goes!)

Here's the project as it stands:

http://clearlytrained.com/depth/

You can drag the boxes then let go over the grid if the grid space is green - if you were to take the two boxes that are one grid space high, place then next to eachother, then take a wider box (2x2) and place it over both (so the gap in the two lower boxes is in the middle of the box you placed on top) you'll see that the far right lower box's depth is now higher and above the box on top. I completley understand why this happens, but no matter how we sweep through the grid in order, this will happen to some extent the way it currently stands.

The way we're currently sorting depth, is sweeping through the grid array, which stores the name of every box on screen, based on the direction we sweep through the rows and columns we get an order to which we then set each box's depth. The problem is that even though a box might take up 6 grid spaces, we don't set the depth 6 time开发者_C百科s - we only set it the first time we come to its instance name in the array - so if we're sweeping through the grid bottom to top, left to right, a box that's physically under another box, yet further to the right will always have a higher depth. not good!

The only way i can see to fix this is to figure out some sort of box to box comparison of first X then Y values, setting up some sort of double for loop/if statemenet conditions, and more or less, programatically hand place each boxe's depth every time we move or place a new box. So the complexity goes from setting depth by order of box instance name, to comparing this box to every other box, then every other box to every other box, and coming up with the real order we need to stack their depth. In some cases we might go left to right, then bottom to top, then back to left to right - there's no smooth pattern.

Please play around with the link provided, let me know if you have any other questions or need more info, I'm desperate!


I would add all boxes to an array and sort that by both X and Y value (tile X and Y). It's not a large set, so you don't really have to worry about performance.

Sort by X, then if X is the same, sort by Y. That shoooould solve it, unless I missed something obvious.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号