我有一个应用程序,我在屏幕上拖动一艘宇宙飞船避开小行星,并希望飞船在它们的矩形碰撞后返回到原来的位置,但它没有发生。
我不确定出了什么问题...
代码:
//Drag Ship
TouchCollection touchLocations = TouchPanel.GetState();
foreach (TouchLocation touchLocation in touchLocations)
{
Rectangle touchRect = new Rectangle
((int)touchLocation.Position.X, (int)touchLocation.Position.Y, shipRect.Width, shipRect.Height);
if (touchLocation.State == TouchLocationState.Pressed
&& shipRect.Intersects(touchRect))
{
shipPressed = true;
}
else if (touchLocation.State == TouchLocationState.Moved && shipPressed)
{
shipRect.X = touchRect.X - touchRect.Width / 2;
shipRect.Y = touchRect.Y - touchRect.Height / 2;
}
else if (touchLocation.State == TouchLocationState.Released)
{
shipPressed = false;
}
else if (lnBtnPlay.Tapped == true)
{
}
}
代码 2:
if (shipRect.Intersects(asteroid1Rect))
{
shipPosition = new Vector2(10, 400);
}