Contact

 
Google
Web www.alanphipps.com

 
 
 
   
www.alanphipps.com

.: The VB.NET XNA Game Engine

 
 

The XNA Game Engine is the basic components needed for you to begin creating your own game in VB.NET. This engine, when run will simply display the game window but draw nothing except the black background. Many components, such as audio and the content pipeline exist and are ready to be used. I will be updating the engine as I learn more XNA techniques.

Please use/modify my code as you see fit. Thanks

 

XNAEngine - The main component.

At the bottom of the class is the main module, this module contains the starting point for the game, XNAGame.Run(). When the game starts it creates the necessary objects and loads the games content. The content is all the textures, sounds, etc that will have been converted to xnb files as per the Content Pipeline. The game then takes the following path:

1 - Sub Main

2 - Sub New

3 - Sub Initialize

4 - Sub Update

5 - Sub Draw

6 - Update and Draw then Loop, one after the other

You should add your update code into the update sub and your draw code into the draw loop, by update code I mean any object movement and any code that is not explicitly used to draw. The Initialize Sub is designed to initially configure objects and variables for their first use. This is a good place to load a texture's file and set it's initial coordinates. The initialize sub contains a line of code which states:

MyBase.Initialize()

This line calls the LoadGraphicsContent Sub, so make sure that this line runs before your code.

 

WriteText - Displays text on the screen - WriteText Tutorial

The writetext class contains only one Sub, Public Shared WriteText. This sub displays text on the screen and all parts, such as text colour, font, size, position and style are configurable. In XNA Version 1.1 Text Drawing functionality is to be added, in that case I will be removing this class

 

Content Pipeline - Converts assets to XNB Files - Content Pipeline Tutorial

'Any Asset to be added to the content pipeline should be listed in this sub,
'using the AddAssettoContentPipeline Sub, example:
'Asset.AddAssettoContentPipeline("Images\Texture.png", Asset.AssetEnum.Texture_Sprite32bpp)

Public Shared Sub AssetList()

End Sub

The only part needed to use the content pipeline is the AssetList Sub. Any asset to be converted should be entered here using the AddAssettoContentPipeline Sub in the following form

Asset.AddAssettoContentPipeline(vbProjectFolder & "\Images\Asset.jpg", AssetEnum.Texture_Sprite32bpp)

 

TextureClass - Displays A Texture On Screen - Texture Tutorial

The textureclass has 2 main subs, Initialize and Draw. Initialize should be put in XNAEngine.Initialize and it creates the texture2D object from a texture file and then assigns values to the texture vertices and configures the effect that will be used to draw the texture. the draw sub should be placed in XNAEngine.Draw and as it's name suggests, it draws the texture to the screen.

 

SkyBoxClass - Creates and displays a Skybox on screen - 3D SkyBox Tutorial

The skyboxclass has 4 main subs. The first Initialize, creates the skybox from 6 textures of your choosing and then configures effects , vertices and the skybox dimensions. The next sub OnDeviceReset, reinitializes the skybox if the graphics device is lost. The Update sub repositions the skybox if the variable LockSkyboxIntoCameraPosition has been set to true and lastly the Draw sub updates the skybox's camera views and the draws each of the six textures.

 

Quaternion Camera - Allows movement of view using the mouse and arrow keys - 3D Camera Tutorial

The camera class has 3 main subs, initialize and draw are near enough identical and they position the camera then set its field of view. The Update sub takes in the mouse movement and arrow key presses, and change the camera's position and direction using quaternion maths. Currently there is only 1 type of camera, freeview, this means that the movement of the camera is not restricted in any way, eventually I will also create a First and Third person camera as well. Keys A and D now control Camera Roll

TerrainClass - Loads values from a heightmap and renders them as terrain.- TerrainTutorial

The terrain class has 2 main subs. Initialize does most of the work, it takes a heightmap, which can be a bmp, jpg or png file and loads the RGB data from it. These values become the Y coordinate of the terrain. The initialize sub takes the various parameters that will determine how the terrain is drawn. The draw sub draws the terrain to the buffer.

 

Sound - Plays sound during the game - Sound Tutorial

The sound class will be updated in a later tutorial as 3D sound functionality will be added to XNA in version 1.1

Public Shared AudioEngine As AudioEngine
Public Shared WaveBank As WaveBank
Public Shared SoundBank As SoundBank
' Thread and Sound to be used for playing the background music
' Public Shared MusicThread As Thread
' Public Shared MusicTrack As New Sound

The sound class requires an AudioEngine, a Wavebank and a SoundBank, you can have more than one but having only one keeps it simple.

 

Private Cue As Cue
Public CueName As String

A Cue is basically a track and the CueName is the track name as set in the soundbank.

 

Public Sub Play(ByVal Cue1 As Cue)

Try
Cue1 = SoundBank.GetCue(CueName)
Cue1.Play()
Catch ex As Exception
End Try

End Sub

To Play a sound, use the Sound.Play sub.

 

Public Sub StopAudio(ByVal Cue1 As Cue)

Try
Cue1 = SoundBank.GetCue(CueName)
Cue1.Stop(AudioStopOptions.Immediate)
Catch ex As Exception
End Try

End Sub

To stop a particular track, use the StopAudio sub.

 

Public Shared Sub InitializeEngine()

'AudioEngine = New AudioEngine("..\..\Audio\gameaudio.xgs")
'WaveBank = New WaveBank(AudioEngine, "..\..\Audio\Wave Bank.xwb")
'SoundBank = New SoundBank(AudioEngine, "..\..\Audio\Sound Bank.xsb")

'Initialize background Music
' MusicTrack.CueName = ""
' MusicThread = New Thread(New ParameterizedThreadStart(AddressOf MusicTrack.Play))

End Sub

The Initialize engine sub should be put in the XNAGame.Initialize sub. I have setup a Track called Musictrack which was designed for background music, it has been multithreaded.

 

Public Shared Sub UpdateEngine()
AudioEngine.Update()
End Sub

Put the AudioEngine.Update sub in the XNAEngine.Update Sub

 

I will update this page as I update the Engine.

 

XNAEngine Source Code - 187Kb

 

     
 
 
     

 

Web site contents © Copyright Alan Phipps 2006, All rights reserved.
Website templates
   
 
 

 

__PayPal

 
Please Donate to the Nvidia Geforce Go 7950 GTX Fund, All donations welcome. Thanks.