本文介绍了重复定时器事件 10 次然后结束它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何制作一个计时器,当它运行时运行大部分代码 10 次,然后在第 10 次运行 Timer2.Stop()

How would I make a Timer that when its ran runs most of its code 10 times then after then 10th time it runs Timer2.Stop()

下面的代码让怪物向右移动 5 个像素然后停止,我希望它移动一个像素 5 次然后运行 ​​right.Stop() 和 Timer1.start()

The code below makes the monster move right 5 pixels then stop, i want it to move one pixel 5 times then run the right.Stop() and Timer1.start()

如果有人能帮我解决这个问题,那就太棒了:D

If someone could help me fix this that would be awesome :D

 Private Sub right_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles right.Tick
    Timer1.Stop()
    If Me.mob2.Location.X < 750 Then
        Me.mob2.Location = New Point(Me.mob2.Location.X + 5, Me.mob2.Location.Y)
    End If
    right.Stop()
    Timer1.Start()
End Sub

推荐答案

试试这个:

Private Sub right_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles right.Tick
    Timer1.Stop()
    Static moveCount as Integer = 1
    If Me.mob2.Location.X < 750 Then
        Me.mob2.Location = New Point(Me.mob2.Location.X + 1, Me.mob2.Location.Y)
    End If
    moveCount += 1
    ' edit this for how many times you want it to move
    If moveCount = 5 Then
        right.Stop()
        moveCount = 1
        Timer1.Start()
    End If
End Sub

这篇关于重复定时器事件 10 次然后结束它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:14