|
|
发表于 2005-11-21 04:15:00
|
显示全部楼层
Re:帮忙写个代码
我现在写出我怎么结合我自己写的2d引擎实现的,是vb.net代码(我的引擎在我发的帖子里面可以下载到,是DX9的,带原码)
Structure AnimationS
Dim Index As Int16
Dim TotalFrame As Int16
Dim CurrentFrame As Int16
Dim Gueltig As Boolean
Dim X As Int16
Dim Y As Int16
Dim Weith As Int16
Dim Heith As Int16
End Structure
Private Animation(0) As AnimationS,GEngine As GEngine.GEngine'GEngine就是我的引擎
Private GamePath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\"
Private TextP(0) As GEngine.GEngine.StrC
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GEngine = New GEngine.GEngine(me, GamePath)
GEngine.CreateNewBuffer("c:\ditu.bmp", 800, 600, 0, 0, True, True)'地图
Animation(0).Index =GEngine.CreateNewBuffer("c:\renwu.bmp", 60, 40, 400, 300, False, True)'人物
Animation(0).CurrentFrame = 1
Animation(0).X = 400
Animation(0).Y = 300
Animation(0).Weith = 20'单桢的宽度
Animation(0).Heith = 40
Animation(0).Gueltig = True
Animation(0).TotalFrame = 3
GEngine.PrintStr(TextP)
Me.Show()
Timer1.Enable=True'用来控制动画的Timer
Do '主循环
GEngine.Render()
Application.DoEvents()
Loop
End Sub
创建一个Timer,间隔设置成动画刷新率
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim Count As Int16 = Animation.GetLength(0), I As Int16, Weith As Int16, Heith As Int16, Left As Int16
For I = 1 To Count
If Animation(I - 1).Gueltig = True Then
Weith = Animation(I - 1).Weith
Heith = Animation(I - 1).Heith
Left = (Animation(I - 1).CurrentFrame - 1) * Weith
GEngine.ChangeBltRect(Animation(I - 1).Index, Left, 0, Left + Weith, Heith)
GEngine.DisableBuffer(Animation(I - 1).Index, True)
Animation(I - 1).CurrentFrame = Animation(I - 1).CurrentFrame + 1
If Animation(I - 1).CurrentFrame > Animation(I - 1).TotalFrame Then Animation(I - 1).CurrentFrame = 1
Else
If I <> 1 Then
GEngine.DisableBuffer(Animation(I - 1).Index, False)
End If
End If
Next
End Sub
|
|