[Extension] arcade-drawing-utils

so it is supposed to simulate 3d buildings with the player angle and distance scaling the building to provide the 3d effect my problem is my sorting system of the distance of building1 seems to have no effect and z depth doesn’t seem to affect these sprites.

the problem is with your code. let’s take a look at this bit:

so my guess here is that the idea was that each step of this loop would get all sprites that were X pixels away. so, for example, at index 10 it would get all sprites that are exactly 20 pixels away.

however, the way the “get all sprites within radius” block works is that it returns all sprites at that radius or less, meaning at the last step of the outer loop (when the radius is at its maximum), it’s going to get all of the buildings and give them the same z index

i think the easier solution here would be to just get the distance of each building sprite from the player and set the z-index based on that. you’re already calculating the distance in the loop below this one, so you could just alter the z-index there.

but what to set it to? well, we want closer buildings to be above further buildings, so we’re going to need to subtract from some larger number like this:

sprite.z = 1000 - (distance from mySprite)

however, it would probably be a good idea to keep the z-index in a more manageable range. 1000 is pretty high so it will be annoying to put HUD elements overtop it.

so something like this might be better:

building.z = 10 + ((1000 - (distance from mySprite)) / 1000)

that’ll make it so that all our buildings have z index values that are between 10 and 11

2 Likes