This page will tell you how to arrange in which order the video hardware draws things (e.g. sprites on top or behind the foreground, etc.)
There are four layers:
- Sprite layer (every sprite)
- Plane A layer (usually foreground)
- Plane B layer (usually parallax)
- Background layer
Background layer shows the background color wherever isn't covered by any other layer. Also sometimes called the "backdrop", to tell it apart from parallax.
The video hardware will normally show those four layers in that order (sprites on top of plane A, on top of plane B, on top of background). However, every sprite and every tile in plane A and B include a "priority flag": stuff with high priority will always show on top of anything with low priority. This lets you switch the order of the layers, so for example a sprite can hide behind the foreground and such.
Once you throw the priority flag into the mix, the layers are ordered as follows (note that each layer can have both high priority and low priority parts at the same time):
- Sprite layer (high priority)
- Plane A layer (high priority)
- Plane B layer (high priority)
- Sprite layer (low priority)
- Plane A layer (low priority)
- Plane B layer (low priority)
- Background layer
Window plane shares the same layer as plane A, so as far as layer sorting goes, both are the same thing.
The priority flag takes care of the order between each layer, but between sprites the situation is different (since they're all in the same layer).
Sprites are sorted by their order in the sprite table (going by their link order). Sprites earlier in the list show up on top of sprites later in the list (priority flag does nothing here). Whichever sprite ends up on top in a given pixel is what will end up in the sprite layer (and sorted against plane A and B).
If you're using sprites for a HUD, make sure those sprites end up earlier in the list than anything else and are high priority. They will show up on top of everything else.
A low priority sprite layer can end up on top of a high priority one. If they happen to be in the same place as high priority plane A or B, weird stuff will happen. This can be exploited to make a silhouette effect.