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

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

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

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)
This post has been edited by NoBrain: 15 July 2011 - 06:08 AM




MultiQuote









|