Developing games in Visual Basic

Facts about BitBlt

Ropecodes

Masks

Using Bitblt

Mr Sprite

Get the bitmaps into the memory


Developing games in Visual Basic
Visual Basic's main purpose is to make windows applications and not games. But games is the thing that is the most fun to make and you learn very much when you develop games.There is a lot of things to think about when creating a game. You have to think about playability, so you get the right feeling in your game. You have to think about that it runs smooth and that can be hard when you at the same times have to worry about graphics. I'm not talking about making games where the monsters are made out of pictureboxes or any other simple way. If you are going to make games in vb you have to use windows to make it run smooth and to get pictures that aren't rectangularly.
  How do you do when you are going to make a moving picture. You have to fool your eyes by showing many pictures after each other very fast. Your pictures are rectangles when you create them but when using them you will use a another image to put into your picture. The image you add will make one of your colors on the original picture transparent. Does it sound hard? It isn't as bad as it seems. Here you will meet the function that makes all this possible. It is a quite big one with a lot of parameters but when you have spend some time with it you will understand everything about it. Here it is:

Facts about BitBlt
The function you need looks like this: Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long.
What the function does is that it takes a bitmap and cuts out a piece of this bitmap to put into an device context(mostly a picturebox). Now you got a picture in a picturebox.
The last parameter in the function decides how you copy the picture. This is explained in the next chapter.

Ropecodes
The last parameter in bitblt is the ropecode. This tell you how you will copy the picture. This makes bitblt a very good good animating function because it makes the function very flexible. You can copy the bitmap or you can invert the colors at the same time. You can also paste together several bitmaps. There are many ways that you can use bitblt and the purpose of this site is only to give you the basics of the function so you can try it yourself. Here are some ropecode constants:

Const SRCCOPY = &HCC0020 This will only copy the picture to the destination.
Const SRCINVERT = &H660046 This will copy the picture and invert the colors.
Const SRCPAINT = &HEE0086 This will Paint the picture on to the destination.
Const SRCAND = &H8800C6 This will glue a bitamps together with another. Used with masks.


Masks
This a pretty smart way to animate a picture but all bitmaps are rectangular and what will I do if I want another shape? Of course is there a way to us nonrectangeled shapes. It is to use a mask. A mask is a bitmap that contains two colors(normally black/white) I am not 100% sure but I think that the color that are white on the original bitmap must be black on the mask or the opposite. When you got a picture and a mask to that picture you will have to put them together with the bitblt-function by using the ropecode SRCPAINT. Here is a simple example:
BitBlt(pic.bmp, 1,1, pic's width,pic's height, mask.bmp, 1, 1, SRCAND)
BitBlt(pic.bmp, 1,1, pic's width, pic's height, picturebox.hdc, 1, 1, SRCPAINT)

Using Bitblt
This chapter is still under construction!!