简体   繁体   English

矩形的相交问题

[英]intersection issues with rectangles

I am trying to get the aliens to intersect with the shooter and when the intersection takes place, I want to exit the game. 我试图让外星人与射手相交,当相交发生时,我想退出游戏。 However, they pass right through the shooter at the bottom without the code even executing 但是,它们直接通过底部的射击程序,甚至没有执行代码

This is my code: 这是我的代码:

Rectangle rectlauncher = new Rectangle(launcherXPos, 720, launcherImg.Width, launcherImg.Height);
Rectangle rectinvader = new Rectangle(invaders[Count].GetXPos(), invaders[Count].GetYPos(),invaderImg.Width, invaderImg.Height);

if (rectinvader.Intersects(rectlaucher))
   {
    this.Exit();
}

values for code: 代码值:

launcherXPos = 512;

            invaderDirection = -1;
            invaderSpeed = 20;

            invader = new invader[55]; //displays the number entered of 'invaders'

            int XPos = 512;
            int YPos = 100;

Perhaps you are drawing some of your elements with an origin point other than Zero? 也许您绘制的某些元素的原点不是零?

One way to try to fix this is to set a breakpoint at the collision that will be triggered only when you hit Space. 解决此问题的一种方法是在碰撞处设置一个断点,只有在您按下Space时才会触发该断点。 Start playing the game, and when you should intersect, hit space, and go over the values you set in the rectangles. 开始玩游戏,当您应该相交时,按下空格键,然后越过您在矩形中设置的值。 Try figuring out why they don't represent what's really going on. 尝试弄清楚为什么它们不能代表实际情况。

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

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