# .NET Game Programming

## Recommended Posts

I would like to begin programming in games in the .NET framework, but I am unsure of where to start. I have read a lot about the XNA library, but the thing that keeps me away from it is the lack of documentation out there and that it is C# dependent and is not compatible with Mono. I am most familiar with Visual Basic, so it's what I prefer to work with. I'm very familiar with Visual Basic .NET, I'm just unsure of where to begin with game programming. Could someone point me in the right direction?

##### Share on other sites
I personally wouldn't bother with Visual Basic for games (although I might just be blinded with my hatred for VB). C# and XNA are probably the best option if you're just getting into it. If you're so concerned that it works with Mono, why do you need it use .NET???

What platforms are you targetting?

xna info

There is a lot of documentation, and one of the references states that there is a Mono implementation of XNA.

I personally use C++, but that might just be because I work with it at work (and I've been using it for a long time now and am pretty familiar with it).

##### Share on other sites
The reason I prefer it to work with Mono is because my primary computer is Macbook Pro, but I usually use a SonyVAIO for programming. It's just a bit annoying to have to rely on my Windows machine for programmingg, especially if I'm away from home. The reason I prefer Visual Basic over C# is because it's what I have to use at school for my Computer Science class, and now that Visual Basic uses the .NET framework, the only significant difference between C# and Visual Basic is syntax, and I'm just most familiar with Visual Basic and it's what I'm most profecient with. I'll give XNA a go I suppose though.

##### Share on other sites
If you're most familiar with vb.net and want to use mono on your mac, use opengl and sdl. That's a perfectly reasonable route in my opinion. VB.net isn't my language of choice, but I do respect it as a viable choice.

The nice thing is the app you make on your mac will also run in windows.

##### Share on other sites
It depends what you mean by 'game'. It is perfectly possible to write a decent game using GDI+ and not touching a 3D API, in which case any .Net language will be fine and it should run under Mono without a problem. However, if you want a seriously graphical game with 3D effects you will need to look at XNA or at OpenGL.

##### Share on other sites
Well I've figured out how to create a Graphics object and draw an image to the form, but I'm a bit confused on how to animate it. I'm using the Paint event to draw my image and then update it's position, but it only calls the Paint event if I do something like minimize the window. Perhaps I need to be doing something else?

Public Class Form1    Public pos As Point = New Point(0, 0)    Public sprite As Image = Image.FromFile("green.bmp")    Public gdi As Graphics    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint        gdi = e.Graphics()        gdi.DrawImage(sprite, pos)        pos = New Point(pos.X + 1, pos.Y + 1)    End SubEnd Class

##### Share on other sites
there should be a Form.repaint method which will trigger a paint event, at least thats how it goes in Java.

btw, you may want to put the graphics variable as a local variable because it shouldn't be used outside the paint event, and by keeping it global you allow it.

##### Share on other sites
Invalidate() will repaint it for you, however if you don't specify the point you want to invalidate then it will repaint the whole panel.

For example panel1.Invalidate(new Rectangle(0, 0, 32, 32));
That would repaint between 0,0 and 32,32.

##### Share on other sites
Coding for fun has lots of articles about coding games in VB, XNA, C++

http://blogs.msdn.com/coding4fun/archive/tags/gaming/default.aspx

have a gander hopefully one of the tutorials will give you a good start.

##### Share on other sites
Well I figured out the whole refreshing the form as well as double buffering to stop the image from flickering.

Public Class Form1    Public pos As Point = New Point(0, 0)    Public sprite As Image = Image.FromFile("green.bmp")    Public g As Graphics    Public temp As Bitmap = New Bitmap(Me.Width, Me.Height)    Public DrawingArea As Graphics = Graphics.FromImage(temp)    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Timer1.Interval = 20        Timer1.Enabled = True    End Sub    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick        g = Me.CreateGraphics()        DrawingArea.Clear(Me.BackColor())        DrawingArea.DrawImage(sprite, pos)        g.DrawImageUnscaled(temp, 0, 0)        pos = new Point(pos.X + 1, pos.Y + 1)    End SubEnd Class

[Edited by - Weebs on March 22, 2008 4:09:00 PM]

##### Share on other sites
Have you considered Tao?

##### Share on other sites
Or OpenTK?

This like SDL for .Net, only a bit higher level. It's also awesome that you can compile your program e.g. on Windows with VB.Net, and the *same* exe will work on all supported platforms (Windows/Linux and very soon OSX).

Why use this over Windows.Forms/GDI+? Well, it's faster (OpenGL), handles sound (OpenAL), input and math. OpenTK's also quite simple to use. Otherwise, it's mostly a matter of preference - if you are just starting out, Windows.Forms are a perfectly viable and simple solution - if I were you I'd continue on this path, and switch over something else when (if) I encountered limitations.

Edit: Tao is very powerful, but it isn't very beginner friendly. XNA is great too, but it will tie you to Windows (please avoid that :) ).

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627733
• Total Posts
2978837

• 10
• 9
• 21
• 14
• 12