在c# -XNA检测精灵
本文关键字:精灵 检测 -XNA | 更新日期: 2023-09-27 18:08:41
我正在用c#开发一款uno游戏&XNA。在游戏的某个阶段,我需要检测哪张牌在某个特定的位置。所以我们如何通过传递屏幕坐标来检测哪个精灵处于特定位置?
将精灵位置存储在某个变量中,并将屏幕坐标与该变量进行比较。因为精灵覆盖了一个特定的区域,你可能不仅想要存储它的原点,还想要存储它的高度和宽度;一个矩形可以很好地完成这项工作。
的例子:
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!
}
}
}
}