Layer priority

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.)

Priority flag

There are four layers:

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):

  1. Sprite layer (high priority)
  2. Plane A layer (high priority)
  3. Plane B layer (high priority)
  4. Sprite layer (low priority)
  5. Plane A layer (low priority)
  6. Plane B layer (low priority)
  7. Background layer

Iwis says

Window plane shares the same layer as plane A, so as far as layer sorting goes, both are the same thing.

Between sprites

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.

Iwis says

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.