First Step VB6 - Adding an Image

This step of the tutorial gets you to add a background image for your game. This will be the start of a small 2 player Pong like game. This article will go through the following activities:


 * Loading images into your game
 * Drawing images onto the screen

Starting a new project
Lets start by creating a new project.


 * 1) Extract the files from the SDK you downloaded into a new folder
 * 2) Name the folder BallProgram
 * 3) Open the folder and change the VB6 Start Pack.vbp file to BallGame.vbp
 * 4) Double click this file to open a Visual Basic 6

Editing the code
So it is time to get rid of that Hello World code and put some new code in there, we want to start making a simple Pong/Breakout style game with a ball a paddle and a background. Double click on Gamelogic file in the solution explorer and Delete the following code:

Now if you run the program now you should be able to see nothing but a black empty screen 800x600 pixels in size. Remember to run you need to:


 * 1) Use File - Make BallGame.exe...
 * 2) Run copyresourcesvb6.cmd
 * 3) Run the game from the bin folder

Getting the images
First of all we will need the 3 images which you can make yourself with a graphics editing program like Fireworks and save them as a .png file or just download these ones to start off:
 * [[Media:Background.png|Background]] [[Image:Background.png|30 px]] (800 x 600 in size
 * [[Media:Ball.png|Ball]] [[Image:Ball.png|30 px]]
 * [[Media:Paddle.png|Paddle]] [[Image:Paddle.png|30 px]]

Save these images in the images folder of your resources folder of your project. For example on my computer the path is: C:\temp\BallProgram\Resources\images

Once you have done this then we need to add them to the Game Resources part of our program. You will remember we played with the Game Logic before but this time we are adding new element so we need to open up GameResources file from the Solution Explorer and scroll down to the section titled: "Sub LoadImages" and add the following code directly below it: This will add the pictures to our Game Resources and when we refer to the pictures from now own we can use the name "Ball" or "Paddle"

Drawing the images
Now we need to add the background picture to our presently empty black frame. Open up the GameLogic file again, find the Do loop in our code then find the following code just below the start of the loop: Call Graphics.ClearScreen(black) underneath that is where we want to add the code for the background image which is: This code basically says you are drawing the "Background" image positioned from the top left corner(0,0), the image is the same size as the window (800,600) so it takes up the whole background.

If you run this game now make sure you run copyresourcesvb6.cmd again. You only need to run this at the start, and then again whenever you add new resources to the project. This script copies the files from the resources of the project to a location where the game can access it.

And that is it. Now we can make a static image appear of whatever we want where ever we want on the screen the next question is how to get things moving with Sprites and Movement...