Animation is the act of displaying a series of images in order to give the illusion of motion. In this tutorial we'll animate a series of spaceship bitmaps to make it seem as though the spaceship is rotating.
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 surface objects (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 Bitmaps 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!
Click here for sample source code which demonstrates this principle.