In a 2D game, a general method for detecting collision is by using bounding box. This is the solution for a lot of situations where precision is not the most important factor. However, if your game cares whether two irregular objects collide with each other or overlap, the bounding box will not be comfortable with the. At this moment, per pixel collision will help you. In this recipe, you will learn how to use this technique in your game.
PixelCollision2DGame.cs. Then, add the
PixelScene.pngfile to the content project.