Visual Basic循环没有冻结程序?

时间:2014-01-06 19:09:34

标签: vb.net

我在下面制作了一个循环让怪物在我的游戏中移动,当整个游戏冻结时循环运行...任何想法让循环每5秒重复一次?

            Randomize()
        Dim value As Integer = CInt(Int((4 * Rnd()) + 1))
    Do
        If value = 1 Then
            If Me.mob2.Location.X < 750 Then
                Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
            End If
        ElseIf value = 2 Then
            If Me.mob2.Location.Y < 549 Then
                Me.mob2.Location = New Point(Me.mob2.Location.X, Me.mob2.Location.Y + 1)
            End If
        ElseIf value = 3 Then
            If Me.mob2.Location.X > 12 Then
                Me.mob2.Location = New Point(Me.mob2.Location.X - 1, Me.mob2.Location.Y)
            End If
        ElseIf value = 4 Then
            If Me.mob2.Location.X < 750 Then
                Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
            End If
        End If
    Loop

计时器不起作用:

    Private Sub Timer()
    ' Timer.interval = 1000
End Sub

1 个答案:

答案 0 :(得分:1)

不是一个好的解决方案,但这有助于您理解问题

你的屏幕没有刷新的问题试试这个:

    Do

    application.doevents() '' so each time it loops it will refresh your screen

    If value = 1 Then
        If Me.mob2.Location.X < 750 Then
            Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
        End If
    ElseIf value = 2 Then
        If Me.mob2.Location.Y < 549 Then
            Me.mob2.Location = New Point(Me.mob2.Location.X, Me.mob2.Location.Y + 1)
        End If
    ElseIf value = 3 Then
        If Me.mob2.Location.X > 12 Then
            Me.mob2.Location = New Point(Me.mob2.Location.X - 1, Me.mob2.Location.Y)
        End If
    ElseIf value = 4 Then
        If Me.mob2.Location.X < 750 Then
            Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
        End If
    End If
Loop
相关问题