Sprites Overview

"I am a little world made cunningly
Of elements and an angelic sprite."
- John Donne, 'Holy Sonnets'

by Ciaran McCreesh
Created: 13th November 1999
Last Modified: 27th November 1999

This page will explain what sprites are and how they work.

What are Sprites?

Sprites are graphics that can be drawn onto the screen at different coordinates. They are stored in memory and copied to the appropriate place in the video memory ($fc00 to $ffff) as required. The picture below shows a sprite, in this case a spaceship.

Sprite Diagram

This is an 8x8 sprite, the most common size used. You would include a sprite in your code as follows:

SpaceshipSprite:
.db %11111100
.db %00101000
.db %01111100
.db %00111111
.db %00111111
.db %01111100
.db %00101000
.db %11111100

As you can see, if a pixel is to be turned on then it is represented by a 1 in memory and if it is to be turned off it is represented by a 0.

Types of Sprite

There are three types of routine that draw sprites, aligned, non-aligned and clipped. Each can draw the same sprite, however the way that the sprite is drawn varies from routine to routine.

Aligned Sprite Routines

Aligned sprites are drawn to a grid on the screen. Each box in the grid is 8x8, so the grid is 128 / 8 = 16 horizontally by 64 / 8 = 8 vertically. The top left corner of the screen is (0, 0).

Non-Aligned Sprite Routines

Non-aligned sprites can be drawn anywhere on the screen. The top left of the screen is (0, 0) and the bottom right is (127, 63). However, if a sprite is drawn too close to the edge of the screen it is not 'clipped' - that is the remains of the sprite might be drawn one pixel higher or lower on the opposite side.

Clipped Sprites

Clipped sprites can be drawn anywhere on the screen, even at the edges. The sprites are 'clipped' by the routine - if part of the sprite is off the screen it will not be drawn anywhere.