Game dev
Saved & recent

Sorting order

Also called: draw order, z-order

Related terms: sorting layer, Y-sort, painter's algorithm

2D sprites are drawn one after another, and later ones cover earlier ones. This is the painter's algorithm. Sorting layers and order numbers fix the sequence: background, characters, effects, UI.

In top-down games, Y-sorting draws sprites that are lower on the screen later. A character can then walk behind a tree and in front of it with no extra work.

Further reading
Unity Manual: 2D rendering order
character behind feet higher character in front feet lower +Y
Compare the character’s feet with the base of the tree. Sprites with a lower ground point on the screen are drawn later, so the overlap reverses when the character passes the tree.

View in the full Game dev collection