Sprite position layer 2D

Advanced game related topics
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 637
Joined: Fri Dec 04, 2015 9:26 pm

Sprite position layer 2D

Post by skinkairewalker »

hello everyone !
i am trying to set sprite layer on plane like this >

screenshot > https://prnt.sc/24p5q5c

is there any shape that is not too complex or complicated?
CharlesT
User
User
Posts: 19
Joined: Sun Jan 07, 2018 10:09 pm

Re: Sprite position layer 2D

Post by CharlesT »

Hi, skinkairewalker. If I understand, you wish to draw the sprites that are lower on the screen over the ones that are higher up. One way would be to make a "render" structure, with fields for sprite ID, x and y coordinates. Then make a structured "zSort" list using the "render" structure. In your "sortAndDraw" procedure, copy the sprite ID, x and y coordinates of your game characters and objects into the zSort list, then sort the list in ascending order by y coordinate. Finally, run a for/next loop to draw all the sprites on the list in the correct order. Make sure to clear the list at the end of the procedure.

Note: You might also need x and y offset fields in your "render" structure. That way, the regular x and y coordinates can refer to some constant position in the characters, such as between their feet, while the offsets control where the sprites are drawn relative to that position.

I'm kind of a novice myself, and there are probably faster ways of doing this, but I hope this helps.
Post Reply