Drawing sprites in the right order

_felix

Member
This here is supposed to be a wheat field (used sprites are placeholders). They're all sprites being drawn by one object, the positions being stored in an array. While assigning the positions it checks whether they're within a certain radius to get the circular shape. This means the sprite positions are determined in a random order, which causes the sprites to be layered on top of eachother randomly. How can I draw the sprites in a way that assigns depth correctly, so that the sprites closer toward the bottom appear to sit front of the ones higher up?

Thanks

Annotation 2020-08-24 154349.png
 

curato

Member
assuming the bottom is closer than the top you would want to draw them from the top to bottom that way the things closer draw over the things further away. You will need to so something a little more complicated than draw x number of sprites in the this radius. Like if you want it in circles a little trig would tell you the line of wheat to plant and draw a random number of wheat along that line and move down like that. It you don't want to do the trig then I would suggest a square , but the key point when you are drawing to the screen you must always draw from the background to the forground to the the depth right otherwise background items will overlap closer things.
 
Top