sprites and animation concept (Lecture 8 Game Development)

abdulrafaychaudhry 27 views 7 slides May 31, 2024
Slide 1
Slide 1 of 7
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7

About This Presentation

sprites and animation concept (Lecture 8 Game Development)


Slide Content

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’
•(Bit blit is a data operation commonly used in computer graphics in which
several bitmaps are combined into one using a boolean function. The
operation involves at least two bitmaps, one source and destination,
possibly a third that is often called the "mask" and sometimes a fourth used
to create a stencil.)
•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
spritepacman[ 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