Keywords: VB.NET DirectX DirectDraw 9 Author: Dong Jun containing reproduced please specify from: http://blog.9cbs.net/a11s
================================================================================================================================================================================= Today, due to time relationship, it is not a task.
Find a foreign site, the people inside compared to the bull x directly to read WAVs in BinaryReader
It's better to be your own ~~~
================ End nonsense =================================
Many people think that DirectDraw is endped in the DirectX7 era, to VB.NET and managed DirectX.
Microsoft should inherit the old DirectDraw and hosted. So DDRAW has changed after all.
Pick up now. It is not suitable. But the basic concept still does not change.
Domestic masters disdain, and someone will host the enemy 2D after 3D, I will not post a comment, but let me have a chance to fill the domestic gap. First, the big process is the foundation, not to reflect DDRAW. Performance, but clarifying steps (more troubles from Microsoft)
0 Project Add DirectDraw, code in IMPORTS Microsoft.directx.directDraw
1 Create a Device to set the collaboration level (as long as DirectX is like this)
2 Create a description (in order to create Surface, create a buffer description with DirectSound)
3 Using the description to create a main buffer and the secondary buffer (that is, BACKSURFACE) 4 is the main buffer specified a clipper ============= 加 加 完成 ============== ==== Drawing process is relatively simple, you can use Timer setting time interval. But the average person will not make this, although the process is simple. In order to reflect smooth animation, it is often used to use the CPU, the higher the FPS, the higher the fps, the higher the fps It's useless, but it is useful when animation is complicated) The following is a timer that refers to the big wind.
DIM TFP AS INTEGER = 0 '' FPS
DIM myTime as date = datetime.now '' 'temporarily used
While (Run = true) '' 'If the game is not over
BLT () '' 'main drawing process
TFP = 1 '' 'FPS
IF TFP = 200 Then '' '200 times calculation time TFP = 0
DIM TS AS New TimeSpan
TS = (datetime.now.subtract (myTime))
Mytime = datetime.now
IF ts.totalseconds <> 0 THEN
DIM qiqi as double = 200 / (ts.totalseconds)
Me.Text = qiqi.tostring ("##. ##") "f C"
END IF
END IF
Tt.sleep (20) '' 'hard regulation is taken, of course, you can go to the MAX speed
End while
Need to know that the variables inside are temporary, if you are very concerned about the speed, this is not advisable, but in order to understand convenience, so it will take it out when you optimize it. With the counter, Use it to establish a game cycle. Cyclic management of the main BLT () process, BLT is also very simple
SUB BLT ()
IF ps is nothing kil
DIM R1 AS Rectangle
DIM R2 AS Rectangle
R2.height = desc2.height
R2.Width = desc2.width
R1.height = p.size.height
R1.x = 0
R1.Y = 0
R1.Width = p.size.width
Ps.draw (R1, BS, R2, DrawFlags.wait)
End Sub
That is to set the rectangular area and then draw it. This is no longer DDRAW7 Rect. How many changes are in it. The call is very simple, directly main2 can, but not, this will make your program "Card", resulting The program does not respond to a new thread to handle this thing
Private sub Label2_Click (Byval e as system.Object, byval e as system.eventargs) Handles label2.click
Run = not run
IF tt is nothing then
Tt = new threading.thread (addressof main2)
Tt.start ()
END IF
End Sub
OK, there are so many things to pay attention to, the following is all source code =================================== ===
Imports Microsoft.directx.directDraw
Imports Microsoft.directX
Imports system.drawing
Public Class Form1
Inherits System.Windows.Forms.form
Dim dev As Device
DIM PS as Surface
DIM BS As Surface
DIM DESC AS SURFAedScription
DIM DESC2 AS SURFAedScription
DIM CLIP As Clipper
DIM T as new date
DIM Run as Boolean
Dim tt as threading.threadConst fn = "d: /nerv.bmp"
#Region "Windows Form Designer Generated Code"
Public Sub New ()
Mybase.new ()
'This call is required for the Windows Form Designer.
InitializeComponent ()
'Add any initialization after INITIALIZECOMPONENT ()
End Sub
'Form rewriting Dispose to clean up the list of components.
Protected Overloads Overrides Sub Dispose (Byval Disposing as Boolean)
IF Disposing then
IF not (Components Is Nothing) THEN
Components.dispose ()
END IF
END IF
Mybase.dispose (Disposing)
End Sub
'Windows Form Designer
Private Components as System.comPonentModel.icontainer
'Note: The following process is necessary for the Windows Form Designer.
'You can modify this process using the Windows Form Designer.
'Don't modify it using the code editor.
Friend Withevents P as System.Windows.Forms.PictureBox
Friend Withevents Label1 As System.Windows.Forms.Label
Friend Withevents Label2 As System.Windows.Forms.Label
Me.p = new system.windows.Forms.PictureBox
Me.label1 = new system.windows.forms.label
Me.Label2 = new system.windows.forms.label
Me.suspendlayout ()
'
'P
'
Me.p.location = new system.drawing.point (40, 48)
Me.p.name = "p"
Me.p.size = new system.drawing.size (640, 480)
Me.p.tabindex = 0
Me.p.tabstop = false
'
'Label1
'
Me.label1.location = new system.drawing.point (16, 16)
Me.Label1.name = "label1"
Me.label1.size = new system.drawing.size (72, 24)
Me.label1.tabindex = 1
Me.Label1.text = "init"
'
'Label2
'
Me.label2.location = new system.drawing.point (112, 16)
Me.Label2.name = "label2"
Me.label2.size = new system.drawing.size (80, 16)
Me.Label2.tabindex = 2
Me.Label2.text = "DRAW"
'
'Form1
'
Me.autoscalebasesize = new system.drawing.size (6, 14)
Me.ClientSize = new system.drawing.size (728, 541)
Me.Controls.add (me.label2)
Me.Controls.add (me.label1)
Me.Controls.add (me.p)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (false)
End Sub
#End region
Private sub Label1_Click (Byval e as system.Object, byval e as system.eventargs) handles label1.click
initdd ()
End Sub
Sub initdd ()
DEV = New Device (createflags.default)
Dev.SetCooperativeEleveLevel (ME, CooperativeElevelFlags.Normal)
DIM CAPS AS New SurfaceCaps
DIM CAPS2 AS New SurfaceCaps
Caps.primarySurface = true
Caps.videMemory = true
Caps2.offScreenPlain = TRUE
DESC = New SurfaceDescription (Caps)
Desc2 = New SurfaceDescription (Caps2)
Desc2.emptyFaceColor = RGB (0, 0, 255)
CLIP = New Clipper (DEV)
Clip.Window = P
BS = New Surface (FN, DESC2, DEV)
PS = New Surface (DESC, DEV)
Ps.clipper = CLIP
Me.text = "loaded"
End Sub
Private sub Label2_Click (Byval e as system.Object, byval e as system.eventargs) Handles label2.click
Run = not run
IF tt is nothing then
Tt = new threading.thread (addressof main2)
Tt.start ()
END IF
End Sub
SUB BLT ()
IF ps is nothing kil
DIM R1 AS Rectangle
DIM R2 AS Rectangle
R2.height = desc2.height
R2.Width = desc2.width
R1.height = p.size.height
R1.x = 0
R1.Y = 0
R1.Width = p.size.width
Ps.draw (R1, BS, R2, DrawFlags.wait)
End Sub
SUB Main2 ()
DIM TFP AS INTEGER = 0 '' FPS
DIM myTime as date = datetime.now '' 'temporarily used
While (Run = true) '' 'If the game does not end BLT ()' 'main drawing process
TFP = 1 '' 'FPS
IF TFP = 200 Then '' 200 times calculation time
TFP = 0
DIM TS AS New TimeSpan
TS = (datetime.now.subtract (myTime))
Mytime = datetime.now
IF ts.totalseconds <> 0 THEN
DIM qiqi as double = 200 / (ts.totalseconds)
Me.Text = qiqi.tostring ("##. ##") "f C"
END IF
END IF
Tt.sleep (20) '' 'hard regulation is taken, of course, you can go to the MAX speed
End while
End Sub
Private Sub Form1_Closing (Byval e as system.componentmodel.canceleventargs) Handles mybase.closing
End
End Sub
END CLASS
============================================================================================================================================================================================================= == Need to note, when drawing, the location of the picture is relative to the upper left corner of the screen, as long as you change the response, you should not reduce this difficulty because the coordinates are involved in other places, so it is not appropriate to reduce this article, so it is not added. One-step DirectDraw full-screen animation, and the character drawing DirectSound mix seems to be very troubles .....