Well guys, I think Ill join your community. I have a good sample of tile based game and a good knowledge in Computer Networks. Ive been working with MDX for 3 months and has good knowledge in D3D 2D Graphics, DSOUND, and DP (client server). Currently, im developing a games which has all the features.
I learned all my DirectX knowledge from 2 books. 1st Tom Millers MDX 9 Graphics and Game Programming (C#). 2nd Games Programming with VB.NET. The 2nd book is greater cause it has many sample games and teach us the game concept such as collision detection, AI, etc.
What im interested now is how to make the MDX application to consume less memory and render at the best performance. Below is the game engine which I extracted from the 2nd book for Device Initialisation.
Well, I wonder how many sprites that the attached tilebased game created?
Thank you.
/*******************************************************
Imports Microsoft.DirectX.Direct3D
Imports Microsoft.DirectX
Public Class clsGameEngine
Protected Shared objDirect3DDevice As Device = Nothing
Simple textured vertices constant and structure
Public Const FVF_CUSTOMVERTEX As VertexFormats = VertexFormats.Position Or VertexFormats.Texture1
defines the default background color as black
Public BackgroundColor As Color = Color.FromArgb(255, 0, 0, 0)
Images path, to be used by the child classes
Protected Const IMAGE_PATH As String = "Images"
Public Structure CUSTOMVERTEX
Public X As Single
Public Y As Single
Public Z As Single
Public tu As Single
Public tv As Single
End Structure
Public Width As Integer = 25
Public Height As Integer = 25
Controls the game end
Public Shared GameOver As Boolean
Public Shared Paused As Boolean
Sub Run()
Do While Not GameOver
If (objDirect3DDevice Is Nothing) Then
GameOver = True
Exit Sub
End If
objDirect3DDevice.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, BackgroundColor, 1.0F, 0)
objDirect3DDevice.BeginScene()
Calls the Render sub - which must be implemented on the derived classes
Render()
objDirect3DDevice.EndScene()
Try
objDirect3DDevice.Present()
Catch
Some error ocurred, possibly in the Render procedure
End Try
Application.DoEvents()
Loop
End Sub
Public Overridable Sub Render()
This sub is specific for each game, and must be provided by the game engine derived class
End Sub
Public Function Initialize(ByVal owner As Windows.Forms.Control) As Boolean
Dim WinHandle As IntPtr = owner.Handle
Dim DispMode As DisplayMode
Dim objDirect3Dpp As PresentParameters
Initialize = True
Try
DispMode = Manager.Adapters(Manager.Adapters.Default.Adapter).CurrentDisplayMode
DispMode.Width = 800
DispMode.Height = 600
Define the presentation parameters
objDirect3Dpp = New PresentParameters
objDirect3Dpp.BackBufferFormat = DispMode.Format
objDirect3Dpp.BackBufferWidth = DispMode.Width
objDirect3Dpp.BackBufferHeight = DispMode.Height
objDirect3Dpp.SwapEffect = SwapEffect.Discard
Enable the stencil depth, since we are working with
non-transformed vertices
objDirect3Dpp.EnableAutoDepthStencil = True
objDirect3Dpp.AutoDepthStencilFormat = DepthFormat.D16
objDirect3Dpp.Windowed = True
Create the device
objDirect3DDevice = New Device(Manager.Adapters.Default.Adapter, _
DeviceType.Hardware, owner, CreateFlags.SoftwareVertexProcessing, _
objDirect3Dpp)
Turn on ZBuffer
objDirect3DDevice.RenderState.ZBufferEnable = True
Tells the device which is the format of our custom vertices
objDirect3DDevice.VertexFormat = FVF_CUSTOMVERTEX
Turn off culling => front and back of the triangles are visible
objDirect3DDevice.RenderState.CullMode = Cull.None
Turn off lighting
objDirect3DDevice.RenderState.Lighting = False
Turn on alpha blending, for transparent colors in sprites
objDirect3DDevice.RenderState.SourceBlend = Blend.SourceAlpha
objDirect3DDevice.RenderState.DestinationBlend = Blend.InvSourceAlpha
The sprite objects must turn on alpha blending only if needed, using the following line:
objDirect3DDevice.RenderState.AlphaBlendEnable = True
Set the Projection Matrix to use a orthogonal view
objDirect3DDevice.Transform.Projection = Matrix.OrthoOffCenterLH(0, DispMode.Width, 0, DispMode.Height, -200, 200)
Catch de As Exception
MessageBox.Show("Could not initialize Direct3D. Error: " & de.Message, "3D Initialization.", MessageBoxButtons.OK, MessageBoxIcon.Error)
Initialize = False
End Try
Dispose the used objects
DispMode = Nothing
objDirect3Dpp = Nothing
End Function
Protected Overrides Sub Finalize()
On Error Resume Next We are leaving, ignore any errors
If Not (objDirect3DDevice Is Nothing) Then objDirect3DDevice.Dispose()
objDirect3DDevice = Nothing
GC.Collect()
MyBase.Finalize()
End Sub
End Class
/********************************************************
This is a good start to learn anyway.