Visual Basic Game Programming Tutorial – Part 1 – Building a Game Loop and Frame Counter

In this Visual Basic 2010 game tutorial series, I’ll be covering the basics of simple, 2D game design, from the ground up. I’ll be focusing primarily on RPG style design; however, these techniques can be used with any 2D game.

This VB Game Design Tutorial will be focusing on:
1.) Building a proper game loop
2.) Creating a Frame Counter to monitor performance
3.) Creating a Game Grid for Tile Mapping

In this series we will be focusing on:
Game Loop Design
Handling Mouse Positions and Clicks.
Graphical Tile Maps
Character Movement & User Input
Creating Semi-transparent brushes
Creating stylized dialog boxes for chat, menus, etc.
Saving & Loading Data from Files
Object Animation





Naampie2000 says:

Hey Thanks man! Got me up to speed on this :)

Jessica R says:

FPS Counter isn’t moving

lagwagon501 says:

Great tutorials Thank you for taking the time to make them 😛

iProgramMC // Minecraft PE says:

How to make game logic in one thread, and rendering in another? By the way, good tutorial for games without THAT many elements. I’m rendering the world, and inventory ONLY ONCE, to reuse in the loop, and I get 50-60 fps. Nice. Once the world is rendered, there’s no need to re-render it again.

Nick says:

Cool tutorials man!
Where did you learned all that stuff?

DaWirez|WiredUpMods says:

Since this is pretty old, I’m guessing that by now you’ve learned that = true wasn’t needed for a lot of those statements and that you could’ve used tTicks += 1?

ComputerTutorials says:

Thank you for this tutorial.  Could someone please explain to me the benefits of using this game loop instead of using timers to repeat that code? 

eniking1 says:

Wtf is that?
That’s not a “game-loop”, it’s an CPU-Killer, called endless loop.
An gameloop updates if a particular value reached.
This value called interval.

Guys, an game-loop, requires a game time.
See this:
 Public Property EnabledGameLoop As Boolean
    Public GameLoopTargets As New List(Of GameObjects)
    Private Form As Form

    Public GameTime_Interval As Long
    Public GameTime_Tick As Long

    Public GameTime As New Stopwatch

    Public FPS As Integer

    Public Sub Init(Form_ As Form)
        Form = Form_
    End Sub

    Private Sub Main()
        Do While EnabledGameLoop
            GameTime_Tick = GameTime.ElapsedMilliseconds
            Do While GameTime.ElapsedMilliseconds – GameTime_Tick < GameTime_Interval                 Form.Invalidate()             Loop         Loop     End Sub Greeting

KHF445 says:

hey, aadaerimus, i been watching you for 2 years now! 😀

Christian Ross says:

I get an error that says ” Conversion from string “TPS:” to type ‘Double’ is not valid.” and I don’t know how to fix it. Thanks in advance

Adrian jay says:

I have to say you are a great teacher, so clear and precise.Have you written a book that I can buy with source code for games.

xSnova says:

It’s old but very helpful,thanks a lot

Bryce Carrier says:

For some reason when I first open Visual Basic, The (
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load) does not automatically load. It did the first time I opened the program. But It never has since. It’s kind of a lengthy bit of code, and I don’t understand all the Jargon that goes into it anyway. Am I doing something wrong? How can I fix it?

Nicholas Cossentino says:

If i try to close the form with the X in upper corner I get an error on the g.CreateGraphics .
I tried to set IsRunning to false to keep the Procedure from attempting to use an already disposed object, but it didn’t help. I did this through a contextMenu and had one option “Quit”
I then had IsRunning to False and the had Me.Close. I still got the exception error for trying to still use an object that is disposed.

‘draw back buffer to screen
‘when i X out the form while running i get:
‘make sure you have not relased a resourse before attemting to use it exception error
‘ cannot access a disposed object error

BBG = Me.CreateGraphics ‘this is where the program crashes

BBG.DrawImage(BB, 0, 0, Me.Width, Me.Height)

angeallionheart says:

i have a question im building a text based rpg, and im new to visual basic and currently use 06. i was wondering how to make global variables that can be seen by all forms. This is for the leveling up, stat, and battle forms. thank you for the help in advance

Jtancos1 says:

this doesnt work for me at all i tried to code it and nothing shows up i triple checked and i have all the right code 😛 

How R_U says:

When I run it, I only see one square at left top corner? What’s wrong? Thank you :)

kevnar says:

With Booleans, you don’t need to add = True. You can just refernce the variable name and it returns true or false. So,

Do While isRunning
‘ Do stuff here

is fine. It does exactly the same thing.

Operators return true or false, too. So you can write more efficient code by using just a comparison with an operator. For example,

Dim playerDead as Boolean
Dim playerHP as Integer

playerDead = (playerHP < 1) If playerDead then MsgBox(“Ha ha! You suck!”) End End If Here, the operator < returns true or false, and the = assigns it to the variable playerDead. You don’t need the = True here in the If statement either. The variable itself returns true or false, satisfying the condition. Some people might like to write all this code out long hand for easier understanding, but it’s always better to give the compiler fewer things to do.

YUJIN loid says:

Hi there,

I am wondering how I would program a jumping animation?
I am trying to program a game while learning how this language works.
(And also, I reduced the size of the squares to 10 x 10 pixels, but the time ticker doesn’t appear on the right. 
I have also changed the ticks per second’s position to 310, 0 but it still isn’t showing. I am still unsure what is the problem.) <== Solved Thank you. ~YoYo

BizarrePlatinum says:

Nice, had to change a bit of code to get it looking right on my screen, but it wasn’t too much, thanks for the tutorial :).

Seth Sweeney says:

I can’t figure out what i’m doing wrong. I got to the test open @ 30:30-32:00, and I’m not getting the tick counter and when i close the window it says “An unhandled exception of type ‘System.ObjectDisposedException’ occurred in System.Windows.Forms.dll … Additional information: Cannot access a disposed object.” looked over everything and I’m not seeing any mistakes. 

Patrick Stumps Fedora |-/ says:

Hey so I’m building this using VB 2010 Express and I cant seem to find my tick counter? Its not there and I’m not 100% where I’ve gone wrong

Serj2 says:

Help me please anybody! How to create an inventory for the game in VISUAL BASIC. NET (the game in the genre of the quest)? So that when you press the PictureBox object – this object was placed in your inventory, and when you right-click on the object in the inventory it can be to move the cursor, and use this object (say the object – key) to the object of the “door” on the form. HELP ME PLEASE. Can anyone help or share source code example?
Sorry for my bad english…

Poodz says:

Incredible Tutorial for beginners

first name says:

this is an awesome video
there are so many in java and C++
its great to see one in

Aldrex Binobo says:

This is a really great video tutorial. Very easy to understand and works perfectly. I’m working on a project and I chose vb to make a simple 2d game, and this video is a great help. I’d give it 10 thumbs up if I can

Oliver D says:

For those of you who are getting 0 tps, pop drawGraphics in startGameLoop, not the main sub!!!

Kochos says:

very cool boss. Thx for the upload

Carlos Lusquinhos says:

Hi bro! This is a great and simple tutorial. Congrats. You have another follower :).

Ian Graham says:

For some reason the ticks counter won’t show.

Márcia Sena says:

Hey Aarderimus, I need of Help In Somethings in Like Error (object Disposed Exception) In BBG = Me.CreateGraphics() , Can You Add me In Facebook or Tell me Your E-mail? Here’s My Facebook Thank You!!!

Emma Darcy says:

Hey, this is ace.
I only get one problem which is the grid loads and then my form design loads over the top of it and you can no longer see the grid.
Is there any particular reason for this other than just having a buttons etc on my form already? Is there a way to get around this? 

Eva Le Bihan says:

Hi! I love your videos!
I’ve just got one thing…
You see, when the ticks & tps’ change (at 33:00 of the video), mine don’t. Everything else seems to be the same though
Here’s my tick counter if it helps

Private Sub TickCounter()
        If tSec = TimeOfDay.Second And IsRunning Then
            tTics = tTics + 1
            maxTics = tTics
            tTics = 0
            tSec = TimeOfDay.Second
        End If
    End Sub

havelcode says:

Great video! Can i ask how you got so good and fluent at vb?
I’m just starting to try and create projects and I figured I would follow your tutorials until i can recreate something simple on my own. 😀

Slinky スリンキー says:

Fuck I wish youtube was around when I was at uni

iProgramMC says:

I don’t wanna download any toolkit because any other toolkit is extremely hard to use and, e.g OpenTK only knows about triangles. However I’d rather use OpenTK than GDI+. If there’s a way to downgrade from GDI+ to GDI it would be cool!
As i have seen on interner, here are comparisons: *300 elements
D2D-55 FPS, GDI+-20fps,GDI-50fps,WPF-33fps

Joe Kelly says:

great video, +Aardaerimus D’Aritonyss  i was wandering could you tell me how i would be able to instead of squares, have circles(eclipses) but allow them to overlap when drawing? so with the same code have a user put down where they want to place circles but not have it be brought to the nearest square.

itsMichael629 Films says:

I’m using Visual Studio 2015, is Visual Basic any different for this edition then it was when you created this video?

Mᴀsᴛᴇʀ M says:

I get this error when I try to test it:
An unhandled exception of type ‘System.ObjectDisposedException’ occurred in System.Windows.Forms.dll
Additional information: Cannot access a disposed object.

I’m still pretty new to programming and I don’t know what to do :/ So if you could help me…

Ultracore International says:

Well, Im using VB 2008 Express and it works. But the nut is that i acctually have isometric map D: / Well here’s my big question: How do i add mouse location for my tiles using isometric one? 😮 Can i also use label.text “x: 1 y: 1 format for this? Anyways had to use DrawImage function for that.

Hamood Hamood says:

can i use how can i load the data from gps to this map and animate my body that moving in this map ???

Pinhook Meiosis says:

i usethis video to fall asleep evry day….and it work and learned me how to programLoL

iProgramMC // Minecraft PE says:

Followed up your tutorial, made 2 layers for a sidescroller and its working at 20fps. I did some optimization: e.g. not render tiles when they are air, hide/show the inventory, hide/show the background details. GDI+ does not use the GPU AT ALL and it doesn’t have hardware acceleration. You even included double-buffering, which is ferfect for flicker-less draw! Thanks!
(i’m soon going to move to D2D btw)

Write a comment


Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.

Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours