First Step VB6

From SwinGame

This tutorial guides you through the process of really getting started with the SwinGame SDK. In this tutorial you will learn to open a window, draw images, draw sprites and move, play sounds, and have some interactivity within your game. At the end of the tutorial you should be much more comfortable using the SwinGame SDK and ready to start working on your own game.

OK so at this stage you have:

Now it is time for your first program in Swingame: "Hello World".

Hello World

Follow these steps to get a "Hello World" program working with SwinGame.

  1. Copy the SDK you downloaded into a new folder - call it Hello World.
  2. Open the project file (the .vbp file) - you can double click it in explorer
  3. Open the "GameLogic" source code file. You should be presented with the following code:
Option Explicit
 
 
Sub Run()
    'Your Code goes in here
    Call Core.OpenGraphicsWindow("VB6 Start Pack", 800, 600)
    Call Audio.OpenAudio
    Call LoadResources
    Do Until Core.WindowCloseRequested
        Call Graphics.ClearScreen_ToColour(black)
        Call Graphics.FillRectangle(red, 20, 200, 200, 100)
        Call Graphics.FillRectangle(green, 220, 200, 200, 100)
        Call Graphics.FillRectangle(blue, 420, 200, 200, 100)
        Call Text.DrawText("Hello World", red, GameFont("Courier"), 20, 310)
        Call Text.DrawText("Hello World", green, GameFont("Courier"), 220, 310)
        Call Text.DrawText("Hello World", blue, GameFont("Courier"), 420, 310)
        Call Text.DrawFramerate(0, 0, GameFont("Courier"))
        Call Text.DrawText("Hello World", white, GameFont("ArialLarge"), 50, 50)
        Call Core.ProcessEvents
        Call Core.RefreshScreen_WithFrame(60)
    Loop
    Call Audio.CloseAudio
End Sub

The purpose of this code is to create a starting point for your project. To see what this does you need to do the following steps. This will compile the program, and execute it. After you have had a look close the window.

  1. From the File menu select Make VB 6 Starter Pack.exe...
  2. In the dialog change the output name to HelloWorld.exe
  3. Click the OK button, the game will be compiled and written as an executable
  4. Open a file explorer and navigate to the folder with your game in it
  5. Double click the copyresourcesvb6.cmd file, this will show a window that reports the files being copied, when this closes continue
  6. Open the bin folder in your game project
  7. Run the game by double clicking HelloWorld.exe
  8. Close the window and return to Visual Basic
Tip: Its a good idea to rename the project file before you start.
You can basically read what it is doing
'comments are in green with a single parenthesis at the start like this sentence 

See if you can find the parts of the code that are doing the following things:

  • Loading all the resources you need for the game
  • Opening up a blank screen 800 pixels wide (x axis) by 600 tall (y axis) - see picture below
  • Starting a Loop, inside which it does:
    • Draws 3 filled rectangles setting their sizes and different colours width height and position
    • Putting the game's "Frame rate" up on the screen in the top right hand corner
    • Writing the words "Hello World" 3 times in different colours below the rectangles
    • Writing the words "Hello World" once at the top in large letters
  • Telling the loop to stop when someone closes the window

Screen Layout

Now you do this...

To help your understanding of what is going on in this code do the following:

  • Change the big "Hello World" to your name
  • Move the Red Rectangle so it is in the bottom right hand corner
  • Make the Red Rectangle twice as big

And that is it you have completed your "Hello World" next we look at adding an image.