2
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$ Jul 19, 2017 at 20:05

1 Answer 1

0
\$\begingroup\$

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;
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .