Timbles & .Net

I wrote the initial prototype of Timbles using vb.Net. Now I know many people will scorn at such a thing, but the reality is, I’ve been around the block with development languages – been doing it for long enough – and nowdays, I just want to go the easiest route.

Coding with .Net and VB is pretty straightforward, and you can do almost everthing you could want with them nowdays. I initial intention was to create the prototype using .net and windows forms and the move over to C++ directx when I need to code the game proper. The idea is that it is much easier to work with the prototype before investing time in the final production software.

When doing graphics with a Windows form there are 2 things you need to do. Firstly you must create a seperate user control to draw to, the second is that you need to turn doublebuffering on on that control.


Partial Class canvas
Inherits System.Windows.Forms.UserControl

This means that you can turn doublebuffered to true for this control. Place that control on your form and that is now your render target. Here is an example paint event for that control which we will use to render the game.

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles panel1.Paint

Dim n As New System.Diagnostics.Stopwatch

PlatformDevice.currentGraphicsDevice = e.Graphics

n.Start()

If Not IsNothing(currentPanel) Then
currentPanel.Render()
End If

n.Stop()

PlatformDevice.renderFrameDuration = n.ElapsedMilliseconds

End Sub

This code then tells the current panel to render. And all that needs to be done in there is to draw to the current graphics device.

Place a timer on your control that runs at your required frame rate, and inside the event for this invalidate your control.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

Dim duration As TimeSpan = Now - lastUpdate

' how long did the update actually take
PlatformDevice.updateTime = duration.Milliseconds

Dim n As New System.Diagnostics.Stopwatch

n.Start()

If Not IsNothing(currentPanel) Then
currentPanel.update()
End If

lastUpdate = Now

n.Stop()

PlatformDevice.updateFrameDuration = n.ElapsedTicks

panel1.Invalidate()

End Sub

That’s it… you’d be surprised that you can get pretty good frame rates based on this method. More than enough for 2d games and in particulalry prototypes.

Next I’m going to mention XNA, Direct3d, and C#…

Related Posts:

%d bloggers like this: