1
我有一個應用程序,我在屏幕上拖動一個太空船避免小行星,並希望一旦它們的矩形相撞,船隻會返回到它的原始位置,但這不會發生。碰撞的精靈不會移動到新的位置
我不能確定什麼是錯的......
代碼:
//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);
}