Page 1 of 1

Using XNA in VB.NET Part I

#1 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 14 July 2011 - 07:19 AM

Using XNA in VB.NET Part I
Getting started
Hello everyone :)

I will show you today how to use XNA in VB.NET. So lets start by creating our project. Create new project lets say new Windows Forms Application. Give it a name and lest start. I will name mine XNAGame. Now that your project is created lets create a new Module. Create a new module i will name mine mdlMain. Now in the new module create sub named Main like so:
Module mdlMain
    Sub Main()

    End Sub
End Module



Now that we created this lets make our program starts from this Sub. Click on your project properties
Attached Image

Click and the project properties will open. Lets make the project to start from the Main() Sub.
Attached Image

Uncheck the check box that you see on the pic. And in the startup project combobox select Sub Main choice. Now that we do this you can delete your form from the project we will not need it anyway.
Now lets add XNA references to our project. Click on menu Project -> Add Reference...


Now select .NET tab and add all XNA references
Attached Image

Now that we add this we are almost done. Next we need to add a new class i will name mine Game. Add your class and then make it inherits the Microsoft.Xna.Framework.Game class like so :

Public Class Game
    Inherits Microsoft.Xna.Framework.Game

End Class



Now we need to add the reference to XNA like so
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Media

Public Class Game
    Inherits Microsoft.Xna.Framework.Game
End Class



Now we need to add the basic functions like Initialize, Draw:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Media

Public Class Game
    Inherits Microsoft.Xna.Framework.Game
    'Fields in our game graphic manager etc'
    Dim graphics As GraphicsDeviceManager
    Dim spriteBatch As SpriteBatch
    Public Sub New()
        graphics = New GraphicsDeviceManager(Me)

    End Sub

    Protected Overrides Sub Initialize()
        'TODO: Add your initialization logic here'
        MyBase.Initialize()
    End Sub
    Protected Overrides Sub LoadContent()
        ' TODO: use this.Content to load your game content here'
        MyBase.LoadContent()
        ' Create a new SpriteBatch, which can be used to draw textures.'
        spriteBatch = New SpriteBatch(GraphicsDevice)
    End Sub
    Protected Overrides Sub UnloadContent()
        MyBase.UnloadContent()
        'TODO: Unload any non ContentManager content here'
    End Sub
    Protected Overrides Sub Update(ByVal gameTime As Microsoft.Xna.Framework.GameTime)
        'Allows the game to exit'
        If GamePad.GetState(PlayerIndex.One).Buttons.Back = ButtonState.Pressed Then
            Me.Exit()
        End If
        'TODO: Add your update logic here'

        MyBase.Update(gameTime)
    End Sub
    Protected Overrides Sub Draw(ByVal gameTime As Microsoft.Xna.Framework.GameTime)
        GraphicsDevice.Clear(Color.CornflowerBlue)
        'TODO: Add your drawing code here'
        MyBase.Draw(gameTime)
    End Sub
End Class



Now all that you have to do is to start the game using the main sub like so:
Module mdlMain
    Sub Main()
        Using game As New Game
            game.Run()
        End Using
    End Sub
End Module



Now your game will looks like your have created new XNA project in C#.
Hope you like it and find it helpful :)

Attached image(s)

  • Attached Image

This post has been edited by NoBrain: 15 July 2011 - 06:08 AM


Is This A Good Question/Topic? 2
  • +

Replies To: Using XNA in VB.NET Part I

#2 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Posted 14 July 2011 - 08:30 AM

Well done. I was wondering when we were going to see XNA in VB.NET make an appearance on this site. Good job on the tutorial, .
Was This Post Helpful? 1
  • +
  • -

#3 bflosabre91  Icon User is offline

  • go sabres

Reputation: 105
  • View blog
  • Posts: 1,439
  • Joined: 22-February 08

Posted 14 July 2011 - 09:02 AM

i know this isn't too tough to do but i thought i read they were going to officially support vb with xna sometime soon? any buzz on that?
Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Posted 14 July 2011 - 09:06 AM

They are working on it and it is supposed to be soon. I'm not sure when they are going to be releasing it though.
Was This Post Helpful? 0
  • +
  • -

#5 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 14 July 2011 - 09:51 AM

Thanks Kilorn lots of people lately in VB.NET forum is trying to make games so i hope they switch to XNA now. Hope they find this XNA series that i`m planing to do helpful :)
Was This Post Helpful? 0
  • +
  • -

#6 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1356
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Posted 14 July 2011 - 11:18 AM

We always welcome more traffic in the XNA section. It gets kind of lonely there sometimes.
Was This Post Helpful? 0
  • +
  • -

#7 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 15 July 2011 - 07:27 AM

I have just submitted the second tutorial on drawing sprite hope it gets approved soon(and that i dont mess something up :P) and people to start using XNA with their favorite language instead using picture boxes and stuff :)
Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 465
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Posted 22 July 2011 - 04:28 PM

Using XNA in VB.NET Part II is now approved if you find this tutorial helpful you should check the other one too. I hope you find it helpful too :)
Was This Post Helpful? 0
  • +
  • -

#9 Duke49  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-February 12

Posted 17 February 2012 - 06:31 AM

View Postraziel_, on 14 July 2011 - 07:19 AM, said:

...
Module mdlMain
    Sub Main()

    End Sub
End Module



Hello !

i try your tutorial, i love it ^^
But can you me how to use a window form instead of a module ?

I cant run my game1 class into a form; it show error: "game can't run in the same thread"
Would you explain a PART I tutorial with t he implentation into a form ?

Pleasssseeee raziel ^^
:helpsmilie:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1