Sprite Animation An exercise on filling circles and polygons to create the animated sprite used in ‘Pac Man’
What is a ‘sprite’? It’s a small graphics pixmap image It’s normally stored in off-screen VRAM It’s ready to be copied to on-screen VRAM The copying operation is called a ‘BitBlt’ Several sprites can support an animation Let’s see how to create a sprite array, then synchronize BitBlts with Vertical Retrace
The ‘Pac Man’ sprite 1. Fill a circle with the foreground color 2. Fill a triangle in the background color
The ‘Pac Man’ sprite-array Create an array of sprites, arranged in a sequence that matches the order in which they will be drawn to VRAM
Typical animation loop sprite pacman[ 8 ]; // the array of sprite-images int i = 0; while ( !done ) { draw( pacman[ i ], vramptr ); vsync(); // await next vertical retrace hide( sprite[ i ], vramptr ); i = ( ++i ) % 8; // cycle through sprite array }
Multiple sprite-arrays RIGHT DOWN UP
Demo: ‘sprites.cpp’ Study the source-code for this demo Arrange your sprites in an array Write a sprite-animation loop Incorporate movement in sprite’s location Let user control direction with arrow-keys Store your sprite-arrays in offscreen vram