2013-08-01 16 views
1

我想制作一款游戏。我正在使用pictureboxes。 的概念是,当pcbox击中另一个时,它增加了点。 所以我想要一个像鼠标一样的事件输入图片框 (当一个图片框进入另一个时)。 我想这代码,但它也不是那么高效如何制作一个picturebox.enter事件

If pc1.left = pc2.left - 120 Then 
Call MsgBox("whatever") 
ElseIf pc1.left = pc2.left + 120 Then 
call msgbox("hit") 
EndIf 

回答

0

你应该避免pictureboxes飞来飞去,但这里是我的答案仍然:

Dim rectangle1 as Rectangle = pc1.Bounds 
Dim rectangle2 as Rectangle = pc2.Bounds 

If (rectangle1.IntersectsWith(rectangle2)) Then 
    //whatever 
Else 
    //hit 
EndIf 

甚至

If (pc1.Bounds.IntersectsWith(pc2.Bounds)) Then 
    //whatever 
Else 
    //hit 
EndIf 

这检测任何相框的交集,但正如我所提到的,这不是vb.net中编程游戏的适当方式。

也许你应该考虑阅读this guide关于编程一个简单的乒乓球游戏(没有控制作为演员)。

+0

感谢您的帮助:D –

+0

没有probs;)如果你想编程“有点大”,你不应该使用pictureboxes等,但有点玩vb.net当然没关系。 .. – cdMinix