2

I'm trying to learn game dev, and I'm using some of Oyyou's tutorials. My problem is: I have a list of sprites, using a sprite object, and I would like to know how to check for collisions between different sprites. I have a basic understanding of bounding boxes, and can use them to some extent, but I don't know how to check collisions in a list. Any help would be appreciated. :D

  • Asking how to solve collisions is very general and has been asked many many times on this site. But to help speed up your googling look up SAT or GJK to solve collisions. – Andrew Wilson Jul 19 '17 at 20:05

1 Answers1

0

Bounding Boxes are basically rectangles (mostly). And the rectangle class provides an Intersects(Rectangle) method (https://msdn.microsoft.com/en-us/library/bb464123.aspx)

Depending on your specific usecase you can iterate through your list and check for collisions like this:

foreach (Sprite s in sprites)
    if (mySprite.Intersects(s))
        return true;
Pavel Slesinger
  • 241
  • 1
  • 7