ATTENTION READERS! Lucky's VB Gaming Site is no longer active. For updated game programming information and tutorials, please visit The Game Programming Wiki!
Animation
If you've read the previous few DirectX tutorials, you've likely already figured
out how to do animation, it's not too hard. If not, read on!
Dim Ship(39) as DirectDrawSurface7
Dim i As Integer
For i = 0 To UBound(Ship)
LoadSprite Ship(i), "vegan" & i, SpriteWidth, SpriteHeight, vbBlack
Next
First we have to declare a bunch of surface variables (I've done it here in an array) to hold
the different frames of animation. In this case, we will have 40 different frames, each one
containing a picture of a ship facing a slightly different direction. We can then create the
illusion that the ship is rotating by flipping from one surface to the next in line.
"LoadSprite" is a function (not shown here) that loads a bitmap onto a given surface. If you
don't know how to do this, have a look at the Loading and Displaying a Bitmap tutorial.
The loop here will load all 40 bitmaps (from "Vegan0.BMP" to "Vegan39.BMP") into the array
"Ship".
Dim Direction as Integer
BackBuffer.Blt DestRect, Ship(Direction), SrcRect, DDBLT_KEYSRC Or DDBLT_WAIT
Now when we blt the surface we include the "Ship" array with a variable for the index value.
By changing the index value we change to frame of the ship we display!
Have a look at my DirectX 7 sample project to see it in action.