The information in this article applies to:
SUMMARY
An application that shows an animated image cannot rely solely on Windows
graphical device interface (GDI) functions because they will be too slow.
Instead, the application must create its own set of bitmaps. This article
discusses the process required and provides tips to improve performance and
memory use.
MORE INFORMATIONThere are three major steps to this process:
It is preferable to allocate a single bitmap to store all the different "cels"--the components of the animated scene. The contents of the bitmap should be arranged in a column that is wide enough to hold a single cel; the height is determined by the number of cels. To improve memory usage, the bitmap should be discardable. For example, given the definitions of the three constants below, the following code allocates the correct size bitmap:
To draw into the bitmap, it must be selected into a display context (DC). Allocate a (temporary) compatible DC for this purpose:
In many cases, all cels will share the same background. Rather than drawing
this background several times onto the bitmap, draw it once onto the first
cel and copy it to the other cels, as the following code demonstrates:
After the background is copied, draw the foreground on each cel, using
regular GDI calls (in TRANSPARENT drawing mode). The coordinates for cel
"i" in bitmap hbm are:
If the cels in the bitmap contain sequential images, animating to the
screen is simplified.
To finish this step, release the temporary DC.
At this point, call the BitBlt() function to copy the various stages of the animation sequence to the screen. If the cels in the bitmap contain
sequential images, a simple loop will do the job nicely, as the following
code demonstrates:
When the drawing is done, delete the temporary DC:
It is important to cancel the selection of the bitmap between passes
through the for loop. This allows the bitmap to be discarded if the system
runs low on memory.
Additional query words: 3.00 3.10 3.50 4.00 animation win16sdk
Keywords : kbSDKWin32 kbWinOS310 kbWinOS95 kbDSupport kbWinOS300 |
Last Reviewed: July 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |