Sprites are small rectangular blocks which combine anywhere from one to 16 separate tiles. They come in 16 possible shapes, ranging from a 1x1 to a 4x4 square, and everything in between:
A single VDP pattern index defines the appearance of the entire sprite, which implies a couple of things. First, every tile in a sprite will be displayed with the same palette and same priority level. Second, when you set the horizontal/vertical flip bits, the entire shape will be mirrored. This is actually quite useful for side-scrolling games: characters can be made to face the opposite direction by just flipping a bit.
Because the default set of shapes is quite limited, a common practice is to combine several sprites into more complex objects. Sonic games handle this with "sprite mappings", simple lists of sprite definitions and their relative positioning to one another. When displaying these objects, the target screen coordinate is added to each individual piece, which are then rendered by the VDP as completely separate sprites.
Since there's only one pattern index per sprite, there's also only a single tile address, which becomes the sprite's base tile address. Tiles are consecutively pulled starting from this location in VRAM and used to fill out a sprite's shape, first top to bottom, then left to right as seen above. This does mean that if a sprite wants to use the same tile more than once, it has to be duplicated in VRAM, wasting precious space.
Entries in the VDP's sprite table have a "link field", meaning the whole thing is actually a linked list. The VDP renders the sprite layer by walking down this list once every scanline, reading up to 80 entries and drawing up to 20 sprites. Sprites are only drawn if they cross the current scanline, giving us the Mega Drive's sprite limit: a global maximum of 80 sprites, and a maximum of 20 sprites per pixel row.
Next time, we'll look at sprite sorting.
No comments:
Post a Comment