Sprites - Falmouth-Games-Academy/comp310-wiki GitHub Wiki

Introduction

In computer graphics, a sprite is a two-dimensional bitmap that is meshed into a larger scene.[4] When several smaller images are combined into a single bitmap to save memory, the overall image is called a sprite sheet.

What is a sprite?

A sprite in the NES refers to an 8x8 tile. To get an 8x16 involves inputting two 8x8 tile addresses together, and the PPU should render both tiles side by side6(http://nesdev.com/NESDoc.pdf). These 8x8 tiles are pieced together to create the environment and characters in the game. If the game involves moving sprites it is important to remember they are not joined and each 8x8/ 8x16 sprite must be coded to move individually otherwise, you may find a characters arm or head fly off. The NES(Nintendo Entertainment System) PPU(Picture Processing Unit) supports 64 8x8 or 64 8x16 sprites. 8x16 sprites cover a larger area of the screen. The advantage of using 8x16 sprites is that it takes less CPU time.[1] The sprites can do this because they can be a part of both pattern tables so they can be rendered as a part of the background or as sprites. Such as in Super Mario Bros. 2 where the sprites switch from being background objects to sprites so that they can leave the tile grid[2].

PPU OAM

OAM (Object Attribute Memory)is the internal memory within the PPU this contains a list that can display up to 64 sprites, each sprites information takes up 4 bytes. [3]

  • Byte 0 is the Y position of the top sprite.
  • Byte 1 is the Tile index number.
  • Byte 2 is the attributes.
  • Byte 3 is the X position of the left side of the sprite.

In the context of sprite information in the PPU OAM, the attributes byte holds information on how that sprite will be displayed on screen. When written in binary, some bits of the 8-bit value correspond to values or transformations upon the appearance of the sprite.

76543210
||||||||
||||||++- Palette (4 to 7) of sprite
|||+++--- Unimplemented
||+------ Priority (0: in front of background; 1: behind background)
|+------- Flip sprite horizontally
+-------- Flip sprite vertically

[2]

e.g assigning an attribute value of #%01000001 will flip the sprite horizontally, show the sprite in front of the background, and use the second (0 based count system) colour palette loaded.

Sprite Layering

Due to the graphics and colour palette limitations, it's hard to have large images with lots of colour on the NES. Sprite layering is a technique used to create colourful large sprites, even with the limitations of the NES 5(https://megacatstudios.com/blogs/press/sprite-layering-on-the-nes). Sprite layering makes it possible to have motion, animation and colour depth to an otherwise still image with no motion.

Little Medusa cutscene

Little Medusa Screenshot [5]

Little Medusa cutscene2 Little Medusa cutscene2

Little Medusa Screenshot split [5]

Above shows a cutscene from Little Medusa that uses sprite layering to improve the scene. The face, hair and water are rendered on a separate sprite layer to the rest of the body. Firstly this makes the face stand out more since it uses a different colour palette, secondly, the water flickers each frame to create a translucent effect.

Sprite Restrictions

As mentioned previously there is a maximum number of sprites allowed on screen at a time. There is also a maximum of 8 sprites drawn on each line.

Writing in sprite data

Each sprite has 4 bytes of data assigned to it:

(1) Y position 
(2) Tile number
(3) Atrributes 
(4) X position

The X and Y positions are where on the screen the sprite will be drawn. The tile number corresponds to the sprite sheet, which tile the sprite is in. The sprite attribute is explained above and basically holds information on how that sprite will be displayed on screen.

The code below shows how these values are assigned in a program:

    LDA #120     ; Y position
    STA $0200
    LDA #0       ; Tile number
    STA $0201
    LDA #0       ; Attributes
    STA #0202
    LDA #128     ; X position
    STA #0203

Code from 7(http://www.vbforums.com/showthread.php?858773-NES-6502-Programming-Tutorial-Part-4-Sprite-Movement-And-Declaring-Variables)

References