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

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

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.