0

I'm developing a game of uno in C# & XNA. At a certain stage of the game, I need to detect which card is at certain specific position. So how can we detect which sprite is at a certain position by passing the screen co-ordinates??

4

1 回答 1

0

将精灵位置存储在某个变量中,并将屏幕坐标与该变量进行比较。由于精灵覆盖了某个区域,您可能不仅要存储它的原点,还要存储它的高度和宽度;一个矩形会很好地完成这项工作。

例子:

class Game1
{
    List<Rectangle> cardSpriteAreas; // this is where you store the card's areas

    public void Update()
    {
         Point position = GetInterestingPosition(); // this is the point you want to check
         foreach(var spriteArea in cardSpriteAreas)
         {
              if (spriteArea.Contains(position))
              {
                   // position is contained within the card's area!
              }
         }
    }
}
于 2013-04-10T18:39:21.513 回答