Vb.net 如何使picturebox检测碰撞和反弹?
这是我的碰撞方法,但它只是朝相反的方向反弹Vb.net 如何使picturebox检测碰撞和反弹?,vb.net,Vb.net,这是我的碰撞方法,但它只是朝相反的方向反弹 'Collision Method 1 Dim Col As Boolean = Collision(pxbox, pbpaddle1) If Col = True Then moveRight = Not moveRight moveDown = Not moveDown End If Dim Col2 As Boolean = Collision(pxbox, pbpaddle2)
'Collision Method 1
Dim Col As Boolean = Collision(pxbox, pbpaddle1)
If Col = True Then
moveRight = Not moveRight
moveDown = Not moveDown
End If
Dim Col2 As Boolean = Collision(pxbox, pbpaddle2)
If Col2 = True Then
moveRight = Not moveRight
moveDown = Not moveDown
End If
这是我处理碰撞的函数
Private Function Collision(ByVal P1 As PictureBox, ByVal P2 As PictureBox) As Boolean
If P1.Left + P1.Width < P2.Left Then Return False
If P2.Left + P2.Width < P1.Left Then Return False
If P1.Top + P1.Height < P2.Top Then Return False
If P2.Top + P2.Height < P1.Top Then Return False
Return True
End Function
专用函数冲突(ByVal P1作为PictureBox,ByVal P2作为PictureBox)作为布尔值
如果P1.Left+P1.Width
有几个问题
试着想清楚这一点。如果
P1.Left+P1.Width
则返回false,这意味着您甚至不再检查Y坐标。我认为这里检查的是如果P1.Top+P1.Height如果P1.Bounds.IntersectsWith(P2.Bounds),则砰
当您点击Return False
时,它不会读取后面的行。它从那里退出函数。但是如果你仔细想想,它一次只会击中一侧。