directx7编程,下面是一个卷屏和角色移动的例子-------------Sunday,8.30
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
While True
DoEvents
Sleep 40
dd2.SetForeColor vbRed
x = x + 15: y = y + 1
If x >= 500 Then x = 500: aaa = True
If y >= 8 Then y = 2
aa
Wend
End Sub
Private Sub Form_Load()
setbb
aaa = False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
End
End Sub
mudule中:
Public a As New DirectX7
Public b As DirectDraw7
Public dd1 As DirectDrawSurface7
Public dd2 As DirectDrawSurface7
Public dd3 As DirectDrawSurface7
Public dd4 As DirectDrawSurface7
Public d1 As DDSURFACEDESC2
Public d2 As DDSURFACEDESC2
Public d3 As DDSURFACEDESC2
Public d4 As DDSURFACEDESC2
Public r1 As RECT
Public r2 As RECT
Public r3 As RECT
Public r4 As RECT
Public r5 As RECT
Public r6 As RECT
Public r7 As RECT
Public r8 As RECT
Public k As DDCOLORKEY
Public x, y As Long
Public aaa As Boolean
Public Sub setbb()
Set a = New DirectX7
Set b = a.DirectDrawCreate("")
b.SetCooperativeLevel Form1.hWnd, DDSCL_ALLOWMODEX Or DDSCL_EXCLUSIVE Or DDSCL_FULLSCREEN
b.SetDisplayMode 800, 600, 32, 0, DDSDM_DEFAULT
d1.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
d1.ddsCaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or DDSCAPS_PRIMARYSURFACE
d1.lBackBufferCount = 1
Set dd1 = b.CreateSurface(d1)
d2.ddsCaps.lCaps = DDSCAPS_BACKBUFFER
Set dd2 = dd1.GetAttachedSurface(d2.ddsCaps)
d3.lFlags = DDSD_CAPS Or DDSD_WIDTH Or DDSD_HEIGHT
d3.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
d3.lWidth = 800: d3.lHeight = 600
Set dd3 = b.CreateSurfaceFromFile(App.Path & "/segs/mitch0.bmp", d3)
r1.Bottom = 90: r1.Left = 400: r1.Right = 640
dd2.BltFast 100, 300, dd3, r1, DDBLTFAST_WAIT
dd2.BltFast 500, 300, dd3, r1, DDBLTFAST_WAIT
r2.Bottom = 85: r2.Left = 160: r2.Right = 400
dd2.BltFast 100, 220, dd3, r2, DDBLTFAST_WAIT
dd2.BltFast 500, 220, dd3, r2, DDBLTFAST_WAIT
d4.lFlags = DDSD_CAPS Or DDSD_HEIGHT Or DDSD_WIDTH
d4.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN
d4.lWidth = 640: d4.lHeight = 448
Set dd4 = b.CreateSurfaceFromFile("aa.bmp", d4)
r7.Bottom = 600: r7.Right = 800: r7.Left = 0: r7.Top = 0
dd3.BltFast 0, 0, dd2, r7, DDBLTFAST_WAIT
aa
End Sub
Public Sub aa()
dd2.BltFast 0, 0, dd3, r7, DDBLTFAST_WAIT
If y = 1 Or y = 0 Then r6.Bottom = 64: r6.Right = 64: r6.Left = 0
If y >= 2 Then r6.Bottom = 128: r6.Top = 64: r6.Right = 64 * (y - 1): r6.Left = 64 * (y - 2)
If x = 500 Then
r8.Bottom = 600: r8.Left = 0: r8.Right = 15: r8.Top = 0
r5.Bottom = 600: r5.Left = 15: r5.Right = 800: r5.Top = 0
dd2.BltFast 785, 0, dd3, r8, DDBLTFAST_WAIT
dd2.BltFast 0, 0, dd3, r5, DDBLTFAST_WAIT
dd3.BltFast 0, 0, dd2, r7, DDBLTFAST_WAIT
End If
kk
End Sub
Public Sub kk()
dd2.DrawText 10, 10, Str(x) , False
k.high = 0
k.low = 0
dd4.SetColorKey DDCKEY_SRCBLT, k
dd2.BltFast x, 250, dd4, r6, DDBLTFAST_SRCCOLORKEY
dd1.Flip Nothing, DDFLIP_WAIT
End Sub