【发布时间】:2020-06-07 07:37:33
【问题描述】:
我正在尝试使用 VB.Net 制作一个简单的游戏,它的概念就像是抓鸡蛋。
我的期望是,当鸡蛋落下时(PictureBox1),接球手(PictureBox2)接住鸡蛋,每次接住都得 1 分。我的想法是当鸡蛋的位置与捕手的位置相匹配时,它会增加点。但它没有用。这里有什么建议吗?
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PictureBox1.Top += 5
If PictureBox1.Location.Y = PictureBox2.Location.Y Then
score += 1
Label1.Text = score
End If
End Sub
这是游戏结束的代码:
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
If PictureBox1.Location.Y > 400 Then
Me.Dispose()
MsgBox("game over")
End If
End Sub
【问题讨论】:
-
最好使用单个绘图画布(如
PictureBox)并处理Paint事件来绘制所有内容。类似this.
标签: vb.net timer location picturebox