我怎么说“当两个图片框重叠时” [英] How do I say "When the two picture boxes overlap"
问题描述
我正在做一个简单的游戏项目,其中主角(声音)围绕一个门户移动。然而,他无法碰到其他动人的角色,否则他将失去生命。
I'm doing a simple game project where the main character (sonic) moves around the form towards a portal. However, he cant bump into the other moving characters or he'll lose a life.
所以我想知道如何表达"当pbxsonic与pbxcharacter重叠时,生命-1"在代码中。我正在考虑做
If pbxsonic.top=pbxcharacter.top and pbxsonic.left=pbxcharacter.left Then
pbxlife1.visible= False
但是,我不认为这段代码会起作用,因为它没有效率其他人物的数量超过5.如果有人可以提供帮助,我将非常感激:)
But, I don't think this code would work and It isn't efficient since the number of other characters are more than 5. I would appreciate it very much if someone could help :)
推荐答案
使用 IntersectsWith PictureBox.Bounds 的强>方法。 例如......
Use the IntersectsWith method of the PictureBox.Bounds. For example...
If pbxsonic.Bounds.IntersectsWith(pbxcharacter.Bounds) Then
MessageBox.Show("Intersects")
End If
您可能还想查看我在链接中发布的代码段下文 它显示了如何在表单中移动图像的示例。 在表单上绘制图像而不是使用PictureBoxes之类的控件。 控制
不适用于移动游戏场景。
You may also want to take a look at the code snippet I posted at the link below. It shows an example of how you should move an image in a form. Drawing the image(s) on the form instead of using controls like PictureBoxes. Controls are not meant for moving game scenarios.
  ;
这篇关于我怎么说“当两个图片框重叠时”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!