DirectX5.0 Latest Game Programming Guide DirectDraw Tutorial Articles 3, Create Animation

zhaozj2021-02-11  199

Third, the examples of creating animations are just written to the background buffer, and then turn the background buffer with the main surface, and the speed is not too fast. The following examples DDEX4 and DDEX5 optimize real-time features, making it more like a real game. DDEX4 shows how to set the color key for the surface, how to use the iDirectdrawsurface :: BLTFast method to copy each part of the exterior surface to the background buffer to generate an animation. DDEX5 adds a read tone plate and changing the palette when moving.

1. Color Key and Bitmap Animation describes a primary way to place bitmaps in an exterior buffer in DDEX3. DDEX4 uses the background and a series of wizards (sprite, this example is a ring) to load the exterior surface technology, then use, iDirectdrawsurface :: BLTFast method copies each part of the outer surface to the background buffer . In addition to the functionality in the previous example, the DOINIT function also includes code for setting the color key for the elf. Color Key is a color value for setting transparency. When the hardware block is written, other pixels are written by the pixels set to the Color Key, thereby generating a non-tum-like wizard on the surface. To set the color key code as follows: // set the color key for this bitmap (black) // Note this Bitmap Has Black as entry 255 in the color table. // ddck.dwcolorspacelowvalue = 0xff; // DDCK.DWCOLORSPACEHIGHVALUE = 0xFF; // LPDDSONE-> setColorKey (DDCKEY_SRCBLT, & DDCK); // if we did not want to hard code the para. 0, 0)); Return True; two different methods of setting the Color Key are given. The first method is the 3 line within the comment, first set the range of the Color Key in the DDColorKey structure, then call the idirectdrawsurface :: setColorKey method Set the color key to black (false location map in black as a palette index Item 255). The second method is to call the DDSETCOLORKEY function to set the color RGB value to select Color Key, black is RGB (0, 0, 0). The DDSETCOLORKEY function calls the DDColormatch function, and the DDColormatch stores the color value of the 0,0 position pixels of the bitmap of the LPDDsone surface, and then assigns pixels of 0,0 positions with the supplied RGB value, and shields the color value. After completing this step, the original color can reap back to 0,0 and use the correct color key to call the DDSetColorKey function. After the call is successful, the Color Key is placed in the DDColorKey structure DWColorspaceLowValue, and also copies to DWColorspacehighValue. Members, then call IDirectDrawSurface :: SetColorKey Set Color Key. CLR_INVALID is another useful variable in the DDSetColorKey and DDColormatch functions. If this value is used as a color key in DDSETCOLORKEY, the pixels in the upper left corner of the bit are used as the Color Key. To achieve this, you need to transfer the bitmap file all.bmp, turn the pixel value at 0,0 as black, save the changes, then change the call to DDSETCOLORKEY: DDSETCOLORKEY (LPDDSONE, CLR_INVALID); recompile DDEX4 DDEX4 will use the pixel values ​​at 0,0 as the Color Key.

2, the animation DDEX4 in DDEX4 uses the red circle in all.bmp to create a simple animation. Animation consists of 3 spaces of the circles. An example is determined by comparing GetTickCount in Win32 and starting running whether the time running is running. Which ring is retransmond, then use the idirectdrawsurface :: BLTFast method to transfer the background from the exterior surface LPDDsone bit block to the background buffer, then use The COLOR Key that has already set will write the circle into the background buffer. After all the rings are written to the background buffer, call the iDirectdrawsurface :: flip method to flip the background buffer and main surface. 3, dynamic change the palette DDEX5 describes any dynamically changed the palette when the program is run, although this is not always used in the game. DirectDraw really can control the palette well. The following code in DDEX5 puts the palette in the lower half of the all.bmp file: // first, set all colors as unused for (i = 0; i <256; i ) {toruscolors [i] = 0;} // Lock The Surface and Scan The Lower Part (The Torus Area) // and Remember All The Index's We Find. Ddsd.dwsize = SizeOf (DDSD); While (LPDDsone-> Lock (Null, & DDSD, 0, NULL) == DDERR_WASSTILLDRAWING); // Now Search Through The Torus Frames and Mark Used Colors for (Y = 480; Y <480 384; Y ) {for (x = 0; x <640; x ) {Toruscolors [ (BYTE *) DDSD.LPSURFACE) [Y * DDSD.LPITCH X]] = 1;}} lpddsone-> unlock (null); array TorusColors is used to specify the index value of the lower half of the upper half of all.bmp The array is initialized to 0 before use. Then lock the outer surface of the screen to detect if a color index value is used. Array TorusColors starts at the 0th row of bitmaps, the color index value in the array is placed in one byte of the location of the memory by the bitmap surface, which is determined by the LPSURFACE member variable in the DDSurfaceDesc structure, LPSurface points The memory address (Y * LPITCH X) corresponding to bitmap (0, 480). The color index value set in the array is used to detect which colors in the palette are replaced. Because there is no common color between the background and the red ring, there is only those color values ​​that are combined with the circular circle to be replaced.

转载请注明原文地址:https://www.9cbs.com/read-4899.html

New Post(0)