Step 2: Creating a Simple Animation

The DDEx4 sample uses the updateFrame sample function to create a simple animation using the red donuts included in the All.bmp file. The animation consists of three red donuts positioned in a triangle and rotating at various speeds. This sample compares the Win32 GetTickCount function with the number of milliseconds since the last call to GetTickCount to determine whether to redraw any of the sprites. It subsequently uses the IDirectDrawSurface3::BltFast method first to blit the background from the off-screen surface (lpDDSOne) to the back buffer, and then to blit the sprites to the back buffer using the color key that you set earlier to determine which pixels are transparent. After the sprites are blitted to the back buffer, DDEx4 calls the IDirectDrawSurface3::Flip method to flip the back buffer and the primary surface.

Note that when you use IDirectDrawSurface3::BltFast to blit the background from the off-screen surface, the dwTrans parameter that specifies the type of transfer is set to DDBLTFAST_NOCOLORKEY. This indicates that a normal blit will occur with no transparency bits. Later, when the red donuts are blitted to the back buffer, the dwTrans parameter is set to DDBLTFAST_SRCCOLORKEY. This indicates that a blit will occur with the color key for transparency as it is defined, in this case, in the lpDDSOne buffer.

In this sample, the entire background is redrawn each time through the updateFrame function. One way of optimizing this sample would be to redraw only that portion of the background that changes while rotating the red donuts. Because the location and size of the rectangles that make up the donut sprites never change, you should be able to easily modify the DDEx4 sample with this optimization.