August 30, 2006

[XNA] VB Template For XNA Application

Here's a simple template you can use after installing XNA Game Studio Express Edition so you can start coding your XNA apps in VB 2005.

1) Create an empty VB 2005 project.
2) Add references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.Game. Both should be in the GAC.
3) Add a module named Program.vb.

Module Program

Sub Main()
Using game As New Game
End Using
End Sub

End Module
4) Add a class named Game.vb.

Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Components
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Storage

Public Class Game
Inherits Microsoft.Xna.Framework.Game

Dim graphics As Components.GraphicsComponent

Private Sub InitializeComponent()
graphics = New Components.GraphicsComponent
End Sub

Public Sub New()
End Sub

Protected Overrides Sub Update()
' The time since Update was called last
Dim elapsed As Double = ElapsedTime.TotalSeconds
' TODO: Add your game logic here
' Let the GameComponents update
End Sub

Protected Overrides Sub Draw()
If Not graphics.EnsureDevice Then Return


' TODO: Add your drawing code here

' Let the GameComponents draw

End Sub
End Class

There. You now have a functioning XNA game skeleton.

1 comment:

Sam Kalman said...

I haven't jumped on the XNA Express bandwagon yet, but judging from the vb code, it looks like all you have to write is some graphics code and game logic code. Couldn't be that bad, I say!

How robust are the XNA libraries?