简体   繁体   English

2个图片框之间的碰撞检测

[英]Collision detection between 2 picture boxes

I am developing a game and am trying to accomplish collision detection for 2 picture boxes. 我正在开发游戏,并试图完成2个图片框的碰撞检测。 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 秒杀1
picSquare 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/ 我的游戏概念非常类似于: http : //www.flukedude.com/theimpossiblegame/

You are using the wrong property. 您使用了错误的属性。 ClientRectangle is the rectangle relative from the control. ClientRectangle是相对于控件的矩形。 You want to use the Bounds property, relative from the container. 您要使用与容器相对的Bounds属性。 Easy to see in the debugger btw, do practice using it. 在调试器中很容易看到btw,请练习使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM