0
我想要發生一個動作,然後等待3秒鐘,然後繼續執行其餘的代碼。VB定時器倒數
我有一個名爲tmrTurnTimer設計師定時器設置爲3000的間隔Tick事件如下
Private Sub tmrTurnTimer_Tick(sender As Object, e As EventArgs) Handles tmrTurnTimer.Tick
Dim intTimer As Integer = 3
If intTimer > 0 Then
lblEnemyDamage.Text = intHeroAtk.ToString()
intTimer -= 1
Else
tmrTurnTimer.Stop()
lblEnemyDamage.Text = ""
End If
End Sub
我所說的記號事件的主人公已經有三週秒鐘的延遲,希望之後攻擊然而,在敵人回擊之前,只要單擊「Attack」,同時全部都會立即執行英雄和敵方標籤中的傷害。
'Call Attack Sub with Hero damage ranges plugged in
Attack(intHeroAtk, 5, 31, intEnemyHP, 8, 14)
'Display damage done in Enemy damage label
lblEnemyDamage.Text = intHeroAtk.ToString()
'If the enemy health is above zero
If intEnemyHP > 0 Then
'Start timer and display damage from hero in enemy damage label
tmrTurnTimer.Start()
'This is where I would like the program to wait for
'three seconds before proceeding
'Call Attack Sub with Enemy damage ranges plugged in
Attack(intEnemyAtk, 5, 21, intHeroHP, 10, 11)
'Display damage done in Hero damage label
lblHeroDamage.Text = intEnemyAtk.ToString()
DisplayStats(intHeroHP, intHeroMP)
請原諒我,如果這是一個愚蠢的請求。
需要聲明'昏暗intTimer爲整數= 3'的'tmrTurnTimer_Tick'之外方法,否則每次計時器滴答它將被初始化爲3的值,並且永遠不會下降到0.(這只是一個小的觀察,並不能真正解決你所遇到的問題)。 – Bugs
良好的觀察。我會嘗試並報告回來。 – Airvvic
@ Jinx88909在模塊中放置'Public intTimer As Integer = 3'。沒有運氣。它仍然在同一時間進行。 – Airvvic