我现在想知道如何检测与矩形列表的冲突。
Rectanlge Player;
List<Rectangle> BlockHitBox = new List<Rectangle>();我不知道正确的语法。
BlockHitBox.Intersect<>();代码应该检测矩形点击框是否与播放器点击框发生冲突。
我的目标是用玩家不能通过的小矩形创建一个房间,所以我需要一次检测多个碰撞(对于角落)。
发布于 2015-04-23 01:34:57
可以使用Rectangle对象的IntersectsWith方法,如下所示:
var commonSize = new Size(100, 100);
var player = new Rectangle(new Point(0,0), commonSize);
var blockHitBox = new List<Rectangle>
{
new Rectangle(new Point(0, 100), commonSize), // This one will not collide
new Rectangle(new Point(100, 0), commonSize), // This one will not collide
new Rectangle(new Point(0, 99), commonSize) // This one will collide
};
bool collision = blockHitBox.Any(item => item.IntersectsWith(player));https://stackoverflow.com/questions/29804383
复制相似问题