I wrote this demo on September 15th 2006.
The purpose was to develop a sprite engine (XOR to remove/display) that allows developer to concentrate on creating graphics and animation and not worry about shifting bytes, or pixel perfect collision. I also wanted to get as many sprites on the screen at any one time by using the screen refresh to time drawing of each sprite.
- No need for pre-shifted graphics (Frame 1,2 etc), saving memory space
- Pixel perfect collision
- Full screen
On each 1/50th of a second:
For each sprite (1-4):
- check for collision
If more than 4 sprites, we handle it like this (1/25th second)
- LOOP 1
Process first 4 sprites (Remove, draw)
Draw ALL sprite attributes
- LOOP 2
Process remaining sprites
This demo allows for the drawing of 8 sprites. We can do this before the scan line hits the main screen (whilst still in border) if we time sprites right:
The following sprites can appear on the following rows to beat scan line (Flicker/No Visibility):
- Sprites 1 and 2 can appear anywhere on screen
- Sprite 3 can appear on rows 7-22
- Sprite 4 can appear on rows 12-22
The same then applies for 5 and 6,7 and 8 on loop 2. Then, for all the extra time we have before the next screen refresh, we would fill in the remaining time of the second drawing with music, or other animation.
When the sprite is drawn, to avoid flicker, the screen attributes are
- Copied to the attribute buffer
- Sprite attributes are written to the buffer
- The attribute buffer is copied to the screen
You can download the source code and TAP file from http://www.peargames.co.uk/downloads/fsprites.zip
- To run, set up your development environment as described in my previous post, and open “fsprites.asm”.
- In “ConText”, press F9 to compile, F10 to run in “Spectaculator”
I plan to write a detailed walkthrough of the code to explain how it all works, watch this space ;-) !