2个图片框之间的碰撞检测
我正在开发一个游戏,并试图完成两个图片框的碰撞检测。我有一个计时器控件,负责将尖峰(敌人)移向盒子(我的角色)。
这是我的代码:
private void tmrSpike_Tick(object sender, EventArgs e)
{
// Spike moving left interval
spike1.Left -= 6;
if (picSquare.ClientRectangle.IntersectsWith(spike1.ClientRectangle))
MessageBox.Show("sd");
if (spike1.Left + spike1.Width < 0)
spike1.Left = ActiveForm.Width;
}
PicturesBoxes:
尖峰1
picSquare
如何做到当盒子(角色)击中尖峰(敌人)时,它会显示警报?
注意:只有尖峰朝盒子移动。当按下向上键时,盒子只会向上跳跃并下降。我的游戏概念与此非常相似:http://www.flukedude.com/theimpossiblegame/
I am developing a game and am trying to accomplish collision detection for 2 picture boxes. I have a timer control that is responsible for moving a spike (enemy) towards a box (my character).
Here is my code:
private void tmrSpike_Tick(object sender, EventArgs e)
{
// Spike moving left interval
spike1.Left -= 6;
if (picSquare.ClientRectangle.IntersectsWith(spike1.ClientRectangle))
MessageBox.Show("sd");
if (spike1.Left + spike1.Width < 0)
spike1.Left = ActiveForm.Width;
}
PicturesBoxes:
spike1
picSquare
How do I make it so when the box (character) hits the spike (enemy), it shows an alert?
Note: Only the spike is moving towards the box. The box only jumps up and drops down when the up key is pressed. My game concept is VERY similar to this: http://www.flukedude.com/theimpossiblegame/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用了错误的属性。 ClientRectangle 是相对于控件的矩形。您想要使用相对于容器的 Bounds 属性。顺便说一句,很容易在调试器中看到,请练习使用它。
You are using the wrong property. ClientRectangle is the rectangle relative from the control. You want to use the Bounds property, relative from the container. Easy to see in the debugger btw, do practice using it.