Oct 302013

First of all, and this is where beginners could get confused, there is no form in an XNA VB.Net app.
You actually need a module with a main sub calling the run method of your XNA class.

You need to make a class that will inherit from Inherits Microsoft.Xna.Framework.Game and in there you will have to override a couple of methods.

The basic steps/methods are
1-initialise variables in Initialize
2-load your content (audio, fonts, textures) in loadcontent
3-put your update logic in update (check inputs, set new coordinates for a sprite, etc)
4-(re)draw your window in draw

And thats basically it, you are ready to take advantage of all the classes and methods of the XNA framework 🙂

Next article will show a working XNA app.

To make it easy on you, at the end of this article is a template project for vs2013 : copy the zip file in C:\Users\username\Documents\Visual Studio 2013\Templates\ProjectTemplates and VS2013 will propose you to create a XNA project from scratch.

See below for a skeleton class.

Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.Media
Imports Microsoft.Xna.Framework.Input

Public Class Game
Inherits Microsoft.Xna.Framework.Game
'Fields in our game graphic manager etc'
Dim graphics As GraphicsDeviceManager

Public Sub New()
graphics = New GraphicsDeviceManager(Me)
Window.Title = "Test"
graphics.PreferredBackBufferHeight = 300
graphics.PreferredBackBufferWidth = 300
End Sub

Protected Overrides Sub Initialize()
'TODO: Add your initialization logic here'
End Sub

Protected Overrides Sub LoadContent()
' TODO: use this.Content to load your game content here'
End Sub

Protected Overrides Sub 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
End If
'TODO: Add your update logic here'
End Sub

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

VS2013 template


 Posted by at 21 h 36 min

Poster un Commentaire

Me notifier des