liveBook · Manning

Sprite

As explained in Classic Game Programming on the NES: Make your own retro video game

A movable or independently displayed game graphic that appears in front of or behind background tiles.

A sprite is an NES hardware object for a movable game graphic. Unlike background tiles, sprites can sit in front of or behind the tile background, letting the PPU combine layers without redrawing individual screen pixels. Blank sprite pixels reveal the graphics beneath them. section 7.1 section 1.5.2

Sprites are built from 8 × 8 patterns loaded from game ROM into video memory. The PPU uses either 8 × 8 sprites, each made from one pattern, or 8 × 16 sprites, each made from two patterns; one mode applies to every sprite currently displayed. section 1.5.2 section 7.1

The NES imposes practical limits that shape sprite design:

  • Display up to 64 sprites, numbered 0 through 63; lower-numbered sprites are drawn first. section 7.1
  • Display no more than eight sprites on one horizontal row. section 7.1 section 7.7
  • Use separate sprite palette tables, providing another 12 colors alongside the 13 background colors visible at once. section 7.7
  • Choose whether each sprite appears in front of or behind background tiles, and optionally flip its pattern horizontally or vertically. section 7.1

Each sprite occupies four bytes in the OAM table: its vertical position, pattern index, attributes, and horizontal position. Attributes select one of four sprite palettes and hold priority and flip settings. Update OAM either byte by byte or, usually, by copying the complete 256-byte table from CPU memory with sprite DMA during vBlank to save CPU cycles. section 7.1

Figure 7.1 Sprite and tile background layers

Use the layer diagram to see how blank pixels allow sprites and background tiles to show through one another. section 7.1

Table 7.1 The 4 bytes allocated to each sprite in the OAM (view table figure)

Byte

Details

0

Stores the y-coordinate of the top left of the sprite minus 1

1

The index number of the tile pattern to use in either the sprite table for 8 × 8 sprites or both the tile pattern and sprite tables for 8 × 16 sprites

Note: There is only one index value available, so for 8 × 16 sprites, even sprites will get their two patterns from the first pattern table, and odd sprites will get their two patterns from the second pattern table.

2

Stores the attributes of the sprite, made up of the following sections:

Bits 0–1—Indicates which of the four sprite color palette tables to use

Bit 5—Indicates whether this sprite has priority over the background

Bit 6—Indicates whether to flip the sprite pattern horizontally

Bit 7—Indicates whether to flip the sprite pattern vertically

3

Stores the x-coordinate of the top left of the sprite minus 1

Inspect the OAM table to map sprite position, pattern, palette, priority, and flip settings to their four control bytes. section 7.1

Ship and bullet

A player ship can use one sprite while left and right gamepad input changes its position. A second sprite can represent a bullet: an action-button press places it onscreen, then gameplay moves it upward. This turns sprite patterns and OAM positions into visible player objects. section 7.0

Sprites also suit simpler demonstrations such as a bouncing ball and a controller-controlled bat. They provide a reusable way to add independently moving objects while background tiles hold the more static screen layout. section 5.0 section 7.1

How Classic Game Programming on the NES: Make your own retro video game covers it

How deep it goes
Explains layering, sizes, limits, OAM control bytes, and DMA-based updates, without detailing a complete sprite routine.
Examples
Uses a player ship moving left and right, an upward-moving bullet, a bouncing ball, and a controller-controlled bat.
What it assumes
Teaches sprite behavior through a step-by-step NES game template without assuming prior assembly experience.
What you can do after
Operate/configure sprites by choosing patterns, positions, palettes, layer priority, flips, and OAM update strategy.
How it connects
Connects sprites to background tiles, the PPU, video memory, OAM, vBlank, sprite DMA, palettes, and gamepad input.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Game Programming on the NES: Make your own retro video game. The section links point to the parts of the book it draws on.